fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. return 0;
  7. }#include <bits/stdc++.h>
  8. using namespace std;
  9. const long long mod = 1e9 + 7;
  10. const double eps = 1e-9;
  11. const double PI = atan(1.0);
  12. #define readFile freopen("input","r",stdin);
  13. #define writeFile freopen("output","w",stdout);
  14. #define fastIO ios::sync_with_stdio(0);
  15. typedef pair<int ,int> ii;
  16. typedef unsigned long long ULL;
  17. bool cmp(ii a,ii b){
  18. return a.first<b.first;
  19. }
  20.  
  21. struct Node{
  22. Node *l,*r;
  23. int val;
  24. int pref,suf;
  25. int sz;
  26. Node(){
  27. l=r=NULL;
  28. val=pref=suf=0;
  29. sz=1;
  30. }
  31. Node(int val){
  32. this->val = pref=suf = val;
  33. this->sz = 1;
  34. }
  35. Node(Node *l,Node *r){
  36. this->sz = l->sz+r->sz;
  37. this->l = l;
  38. this->r = r;
  39. this->pref = l->pref;
  40. if (l->sz==l->pref)
  41. this->pref+=r->pref;
  42. this->suf = r->suf;
  43. if (r->sz==r->suf)
  44. this->suf+=l->suf;
  45. this->val = max(l->val,max(r->val,l->suf+r->pref));
  46. }
  47. };
  48. const int N=100005;
  49. ii arr[N];
  50. int comp[N];
  51. int n,q;
  52. int st[N];
  53. Node* tree[N+1];
  54.  
  55. Node* build(int l,int r){
  56. if (l==r) return new Node();
  57. int mid=(l+r)>>1;
  58. return new Node(build(l,mid),build(mid+1,r));
  59. }
  60. Node* insert(Node *node,int l,int r,int idx){
  61. if (l==r){
  62. return new Node(1);
  63. }
  64. int mid = (l+r)>>1;
  65. if (idx<=mid){
  66. return new Node(insert(node->l,l,mid,idx),node->r);
  67. }
  68. return new Node(node->l,insert(node->r,mid+1,r,idx));
  69. }
  70. Node* query(Node *node,int l,int r,int ll,int rr){
  71. if (l>rr || r<ll||r<l || rr<ll) return new Node();
  72. if (l>=ll && r<=rr) return node;
  73. int mid = (l+r)>>1;
  74. return new Node(query(node->l,l,mid,ll,rr),query(node->r,mid+1,r,ll,rr));
  75. }
  76.  
  77. int getH(int val){
  78. ii* it = lower_bound(arr+1,arr+n+1,make_pair(arr[st[val]].first,0),cmp);
  79. if (it->first==arr[st[val]].first) return st[val];
  80. return st[comp[(++it)->second]];
  81. }
  82.  
  83.  
  84.  
  85.  
  86. int main(){
  87. #ifndef ONLINE_JUDGE
  88. readFile;
  89. #endif
  90. fastIO;
  91. cin>>n;
  92. for(int i=1;i<=n;i++){
  93. cin>>arr[i].first,arr[i].second=i;
  94. }
  95. sort(arr+1,arr+n+1);
  96. int pointer=1;
  97. comp[arr[1].second] = 1;
  98. st[1] = arr[1].second;
  99. for(int i=2;i<=n;i++){
  100. if (arr[i].first!=arr[i-1].first) {
  101. pointer++;
  102. st[pointer] = i;
  103. }
  104. comp[arr[i].second] = pointer;
  105. }
  106. tree[n+1] = build(1,n);
  107. for(int i=n;i>0;i--){
  108. tree[i] = insert(tree[i+1],1,n,arr[i].second);
  109. }
  110. cin>>q;
  111. while (q--){
  112. int l,r,w; cin>>l>>r>>w;
  113. int ll=0,rr=pointer,res=0;
  114. while (ll<rr){
  115. if (ll>=rr) break;
  116. int mid = (ll+rr+1)>>1;
  117. int h = getH(mid);
  118. int quer = query(tree[h],1,n,l,r)->val;
  119. if (quer>=w){
  120. ll=mid;
  121. }
  122. else rr = mid-1;
  123. }
  124. cout<<arr[st[ll]].first<<"\n";
  125. }
  126. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:7:2: error: stray '#' in program
 }#include <bits/stdc++.h>
  ^
prog.cpp:7:3: error: 'include' does not name a type
 }#include <bits/stdc++.h>
   ^
prog.cpp:11:27: error: 'atan' was not declared in this scope
 const double PI = atan(1.0);
                           ^
prog.cpp: In function 'int getH(int)':
prog.cpp:78:75: error: no matching function for call to 'lower_bound(ii*, ii*, std::pair<int, int>, bool (&)(ii, ii))'
     ii* it = lower_bound(arr+1,arr+n+1,make_pair(arr[st[val]].first,0),cmp);
                                                                           ^
In file included from /usr/include/c++/5/bits/char_traits.h:39:0,
                 from /usr/include/c++/5/ios:40,
                 from /usr/include/c++/5/ostream:38,
                 from /usr/include/c++/5/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/5/bits/stl_algobase.h:996:5: note: candidate: template<class _ForwardIterator, class _Tp> _ForwardIterator std::lower_bound(_ForwardIterator, _ForwardIterator, const _Tp&)
     lower_bound(_ForwardIterator __first, _ForwardIterator __last,
     ^
/usr/include/c++/5/bits/stl_algobase.h:996:5: note:   template argument deduction/substitution failed:
prog.cpp:78:75: note:   candidate expects 3 arguments, 4 provided
     ii* it = lower_bound(arr+1,arr+n+1,make_pair(arr[st[val]].first,0),cmp);
                                                                           ^
prog.cpp: In function 'int main()':
prog.cpp:86:5: error: redefinition of 'int main()'
 int main(){
     ^
prog.cpp:4:5: note: 'int main()' previously defined here
 int main() {
     ^
prog.cpp:95:23: error: 'sort' was not declared in this scope
     sort(arr+1,arr+n+1);
                       ^
stdout
Standard output is empty