Submission #115855

#TimeUsernameProblemLanguageResultExecution timeMemory
115855songcDancing Elephants (IOI11_elephants)C++14
26 / 100
328 ms3064 KiB
#include "elephants.h" #include <bits/stdc++.h> using namespace std; int N, K, M, Q; int Sq; int B[400][1000], sz[400]; int D[400][1000], C[400][1000]; int A[150505], T[150505]; void calc(int t){ if (!sz[t]) return; int k=sz[t]-1; for (int i=sz[t]-1; i>=0; i--){ while (B[t][i] + K < B[t][k]) k--; if (k == sz[t]-1) D[t][i] = 1, C[t][i] = B[t][i] + K; else D[t][i] = D[t][k+1] + 1, C[t][i] = C[t][k+1]; } } void init(int n, int l, int X[]) { N=n, K=l; Sq = 400; M = (N+Sq-1)/Sq; for (int i=0; i<N; i++){ B[i/Sq][sz[i/Sq]++] = X[i]; A[i] = X[i]; } for (int i=0; i<M; i++) calc(i); } void del(int x){ int t, k; for (t=0; t<M; t++){ if (!sz[t]) continue; k = lower_bound(B[t], B[t]+sz[t], x) - B[t]; if (k < sz[t] && B[t][k] == x) break; } sz[t]--; for (; k<sz[t]; k++) B[t][k] = B[t][k+1]; calc(t); } void add(int x){ int t; for (t=0; t<M-1; t++) if (sz[t] && x <= B[t][sz[t]-1]) break; B[t][sz[t]++] = x; for (int i=sz[t]-1; i>0 && B[t][i-1] > B[t][i]; i--) swap(B[t][i-1], B[t][i]); calc(t); } int update(int x, int y) { del(A[x]); A[x] = y; add(y); Q++; if (Q % 400 == 0){ int cnt=0; for (int i=0; i<M; i++){ for (int j=0; j<sz[i]; j++) T[cnt++] = B[i][j]; sz[i] = 0; } init(N, K, T); } int p=-1, ans=0; for (int i=0; i<M; i++){ if (!sz[i]) continue; int k = upper_bound(B[i], B[i]+sz[i], p) - B[i]; if (k == sz[i]) continue; ans += D[i][k], p = C[i][k]; } return ans; }

Compilation message (stderr)

elephants.cpp: In function 'void del(int)':
elephants.cpp:34:12: warning: 'k' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int t, k;
            ^
#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...