Submission #1067304

#TimeUsernameProblemLanguageResultExecution timeMemory
1067304AndreyAbracadabra (CEOI22_abracadabra)C++14
40 / 100
263 ms25936 KiB
#include<bits/stdc++.h> using namespace std; vector<int> haha(200001); vector<int> p(200001,1e7); vector<int> idk(200001); vector<int> bruh(200001); vector<int> pos(200001); int n; void upd(int a, int x) { while(a < idk.size()) { idk[a]+=x; a+=((a)&(-a)); } } bool dude() { int c = 0,sb = 0; for(int i = 18; i >= 0; i--) { if(c+(1 << i) <= n && sb+idk[c+(1 << i)] < n/2) { c+=(1 << i); sb+=idk[c]; } } c++; sb+=bruh[c]; if(sb == n/2) { return false; } int y = pos[c]+bruh[c]-(sb-n/2); while(true) { if(p[y] < pos[c]+bruh[c]) { bruh[haha[y]] = p[y]-y; upd(haha[y],bruh[haha[y]]); } else { bruh[haha[y]] = pos[c]+bruh[c]-y; upd(haha[y],bruh[haha[y]]); break; } y = p[y]; } upd(c,n/2-sb); bruh[c]+=n/2-sb; return true; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int q; cin >> n >> q; for(int i = 1; i <= n; i++) { cin >> haha[i]; pos[haha[i]] = i; } stack<pair<int,int>> troll; for(int i = 1; i <= n; i++) { while(!troll.empty() && haha[i] > troll.top().first) { p[troll.top().second] = i; troll.pop(); } troll.push({haha[i],i}); } int y = 1,big = haha[1]; for(int i = 2; i <= n/2; i++) { if(haha[i] > big) { bruh[haha[y]] = i-y; y = i; big = haha[i]; } } bruh[haha[y]] = n/2-y+1; big = haha[n/2+1],y = n/2+1; for(int i = n/2+1; i <= n; i++) { if(haha[i] > big) { bruh[haha[y]] = i-y; y = i; big = haha[i]; } } bruh[haha[y]] = n-y+1; for(int i = 1; i <= n; i++) { upd(i,bruh[i]); } for(int i = 0; i < q; i++) { int t,a; cin >> t >> a; if(t == 0) { cout << haha[a] << "\n"; } else { if(i == 0) { for(int j = 0; j < t-1; j++) { if(!dude()) { break; } } } int c = 0,sb = 0; for(int j = 18; j >= 0; j--) { if(c+(1 << j) <= n && sb+idk[c+(1 << j)] < a) { c+=(1 << j); sb+=idk[c]; } } c++; sb+=bruh[c]; cout << haha[pos[c]+bruh[c]-1-(sb-a)] << "\n"; } } return 0; }

Compilation message (stderr)

Main.cpp: In function 'void upd(int, int)':
Main.cpp:12:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     while(a < idk.size()) {
      |           ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...