Submission #555539

#TimeUsernameProblemLanguageResultExecution timeMemory
555539fuad27Nekameleoni (COCI15_nekameleoni)C++17
0 / 140
385 ms3976 KiB
#include<bits/stdc++.h> using namespace std; const int MAXN = 5010; const int MAXK = 50; vector<int> fen[50]; void update(int in, int val, int bt) { in++; while(in < MAXN) { fen[bt][in]+=val; in+=in&(-in); } } long long query(int l, int bt) { l++; long long sum = 0; while(l > 0) { sum+=fen[bt][l]; l-=l&(-l); } return sum; } long long k; bool check(int l, int r) { bool c = true; for(int i = 0;i<k;i++) { if(!(query(r, i) - query(l-1, i)))c = false; } return c; } int main () { srand(time(NULL)); long long n, m; cin >> n >> k >> m; for(int i = 0;i<50;i++) { fen[i].resize(MAXN); } long long arr[n]; for(int i = 0;i<n;i++){ cin >> arr[i]; arr[i]--; } for(int i = 0;i<n;i++) { update(i, 1, arr[i]); } while(m--) { int type; cin >> type; if(type == 1) { int p, v; cin >> p >> v; v--;p--; update(p, -1, arr[p]); arr[p] = v; update(p, 1, arr[p]); } else { int p1 = 0, p2 = 0; int lo = k, hi = n; long long ans = 1e9; while(lo <= hi) { int mid = (lo+hi)/2; bool c = false; for(int j = 0;j<20;j++) { int l = rand()%(n-mid+1); int r = l+mid-1; if(check(l, r)){ans = min(ans, (long long)mid);c=true;} } if(c) { hi = mid-1; } else { lo = mid+1; } } if(ans == 1e9)ans = -1; cout << ans << "\n"; } } }

Compilation message (stderr)

nekameleoni.cpp: In function 'int main()':
nekameleoni.cpp:57:8: warning: unused variable 'p1' [-Wunused-variable]
   57 |    int p1 = 0, p2 = 0;
      |        ^~
nekameleoni.cpp:57:16: warning: unused variable 'p2' [-Wunused-variable]
   57 |    int p1 = 0, p2 = 0;
      |                ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...