Codeforces 811 B Vladik and Complicated Book

来源:互联网 发布:软件产品设计流程 编辑:程序博客网 时间:2024/06/05 03:48

题目地址:http://codeforces.com/contest/811/problem/B
题意:Vladik有一本有n页的书,告诉你书的序列(并不是按大小顺序排的),他妈妈帮他整理m次书,每次都把一段序列(l-r)按从小到大的顺序排列,求在这种情况下Vladik能不能找到他要的那一页书(x)
题解:不能每次来排序,那样会超时,每次处理的时候去判断在这个区间内有多少个数比给定那个数的位置上的数小,如果是x-1的话就说明能找到输出“Yes”,否则输出“No”。

#include <iostream>#include <cstring>#include <string>#include <vector>#include <queue>#include <map>#include <algorithm>#define N 10010#define inf 0x3f3f3f3f#define LL long longusing namespace std;const LL mod = 1e9 + 7;int main() {    cin.sync_with_stdio(false);    int n, m;    int a[N];    int l, r, x;    while (cin >> n >> m) {        for (int i = 1; i <= n; i++) {            cin >> a[i];        }        while (m--) {            cin >> l >> r >> x;            int cnt = 0;            for (int i = l; i <= r; i++) {                if (a[i] < a[x]) {                    cnt++;                }            }            if(cnt==(x-l)){                cout << "Yes" << endl;            }            else {                cout << "No" << endl;            }        }    }    return 0;}
原创粉丝点击