Advertisement
makrusak

1613 timus

Jun 18th, 2013
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.01 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <iostream>
  4. #include <algorithm>
  5. #include <vector>
  6. #include <string>
  7. #include <string.h>
  8. #include <queue>
  9. #include <stack>
  10. #include <deque>
  11. #include <map>
  12. #include <set>
  13. #include <cmath>
  14. #include <sstream>
  15. #include <ctime>
  16.  
  17. #define pb push_back
  18. #define mp make_pair
  19. #define PI 3.1415926535897932384626433832795
  20. #define ALL(x) x.begin(), x.end()
  21. #define F first
  22. #define S second
  23. #define m0(x) memset(x,0,sizeof(x))
  24. #define m1(x) memset(x,-1,sizeof(x))
  25. #define pw(x) (1ull<<(x))
  26.  
  27. using namespace std;
  28. typedef long long ll;
  29. typedef unsigned long long ull;
  30. typedef long double ld;
  31. typedef pair<int,int> pii;
  32. const int INF = 2147483647;
  33. const ll LLINF = 9223372036854775807LL;
  34.  
  35. struct qu {
  36.   int l,r,num;
  37. };
  38.  
  39. const int maxn = 200000;
  40. int a[maxn];
  41. int so[maxn];
  42. int ans[maxn];
  43. int col[maxn];
  44. int p[maxn];
  45. int n,qc;
  46. qu q[maxn];
  47. int sc = 0;
  48. int bl;
  49.  
  50. bool comp(int a, int b) {
  51.   return (q[a].l/bl<q[b].l/bl) || (q[a].l/bl==q[b].l/bl && q[a].r<q[b].r);
  52. }
  53.  
  54. int main() {
  55.   //freopen("input.txt", "r", stdin);
  56.   //freopen("output.txt", "w", stdout);
  57.   cin >> n;
  58.   for (int i=0;i<n;i++) {
  59.     scanf("%d", &a[i]);
  60.     so[sc++] = a[i];
  61.   }
  62.   bl = (int)(sqrt(n));
  63.   cin >> qc;
  64.   for (int i=0;i<qc;i++) {
  65.     scanf("%d%d%d", &q[i].l, &q[i].r, &q[i].num);
  66.     so[sc++] = q[i].num;
  67.   }
  68.   sort(so, so+sc);
  69.   for (int i=0;i<n;i++) a[i] = (int)(lower_bound(so, so+sc, a[i])-so);
  70.   for (int i=0;i<qc;i++) q[i].num = (int)(lower_bound(so, so+sc, q[i].num)-so);
  71.   for (int i=0;i<qc;i++) p[i] = i;
  72.   sort(p, p+qc, comp);
  73.   int l = 0, r = -1;
  74.   for (int i=0;i<qc;i++) {
  75.     qu &cur = q[p[i]];
  76.     cur.l--; cur.r--;
  77.     while (r<cur.r) {
  78.       r++;
  79.       col[a[r]]++;
  80.     }
  81.     while (l<cur.l) {
  82.       col[a[l]]--;
  83.       l++;
  84.     }
  85.     while (l>cur.l) {
  86.       l--;
  87.       col[a[l]]++;
  88.     }
  89.     while (r>cur.r) {
  90.       col[a[r]]--;
  91.       r--;
  92.     }
  93.     if (col[cur.num]!=0) ans[p[i]] =1;
  94.   }
  95.   for (int i=0;i<qc;i++) printf("%d", ans[i]);
  96.   return 0;
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement