# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
197089 | 2020-01-18T14:53:15 Z | stefdasca | 코끼리 (Dancing Elephants) (IOI11_elephants) | C++14 | 9000 ms | 7848 KB |
#include <bits/stdc++.h> #include "elephants.h" using namespace std; int sqt = 0; int n, L; int V[150005]; vector<int> bucket[350]; int DP[150005]; int G[150005]; int pos[150005]; int lastbucket = 0; int pot = 0; vector<int> v(n); void rebuild(bool C) { pot = 0; if(C) for(int i = 0; i < n; i++) v.push_back(i); else { v.clear(); int last = -1; for(int i = 0; i <= lastbucket; i++) { for(int j = 0; j < bucket[i].size(); j++) { v.push_back(bucket[i][j]); last = bucket[i][j]; } bucket[i].clear(); } } int currbucket = 0; for(int i = 0; i < n; i++) { if(bucket[currbucket].size() <= sqt) bucket[currbucket].push_back(v[i]); else bucket[++currbucket].push_back(v[i]); pos[v[i]] = currbucket; lastbucket = currbucket; } for(int i = 0; i <= lastbucket; i++) { int curr = 0; int X = bucket[i].size(); curr = X-1; for(int j = X - 1; j >= 0; j--) { DP[bucket[i][j]] = 1; while(curr > j && V[bucket[i][curr - 1]] > (V[bucket[i][j]] + L)) curr--; G[bucket[i][j]] = j; if(V[bucket[i][curr]] > (V[bucket[i][j]] + L)) { DP[bucket[i][j]] += DP[bucket[i][curr]]; G[bucket[i][j]] = G[bucket[i][curr]]; } } } } void erase_elem(int currbucket, int vl) { vector<int> w; for(int i = 0; i < bucket[currbucket].size(); i++) { if(bucket[currbucket][i] == vl) continue; w.push_back(bucket[currbucket][i]); } bucket[currbucket] = w; int i = currbucket; int X = bucket[i].size(); int curr = X-1; for(int j = X - 1; j >= 0; j--) { DP[bucket[i][j]] = 1; while(curr > j && V[bucket[i][curr - 1]] > (V[bucket[i][j]] + L)) curr--; G[bucket[i][j]] = j; if(V[bucket[i][curr]] > (V[bucket[i][j]] + L)) { DP[bucket[i][j]] += DP[bucket[i][curr]]; G[bucket[i][j]] = G[bucket[i][curr]]; } } } void add_elem(int currbucket, int vl) { vector<int> w; bool gone = 0; pos[vl] = currbucket; for(int i = 0; i < bucket[currbucket].size(); i++) { if(V[bucket[currbucket][i]] >= V[vl] && !gone) { gone = 1; w.push_back(vl); } w.push_back(bucket[currbucket][i]); } if(!gone) w.push_back(vl); swap(bucket[currbucket], w); int i = currbucket; int X = bucket[i].size(); int curr = X - 1; for(int j = X - 1; j >= 0; j--) { DP[bucket[i][j]] = 1; while(curr > j && V[bucket[i][curr - 1]] > (V[bucket[i][j]] + L)) curr--; G[bucket[i][j]] = j; if(V[bucket[i][curr]] > (V[bucket[i][j]] + L)) { DP[bucket[i][j]] += DP[bucket[i][curr]]; G[bucket[i][j]] = G[bucket[i][curr]]; } } } void init(int N, int Lx, int X[]) { sqt = 600; n = N; L = Lx; for(int i = 0; i < N ; i++) V[i] = X[i]; rebuild(1); } int update(int ix, int yx) { erase_elem(pos[ix],ix); int oldd = pos[ix]; V[ix] = yx; int newbucket = lastbucket; for(int i = 0; i < lastbucket; i++) if(bucket[i+1].size() && V[bucket[i+1].front()] >= yx) { newbucket = i; break; } add_elem(newbucket, ix); pot++; if(bucket[oldd].size() == 0 || pot >= sqt) rebuild(0); int currpos = 0; int currbucket = 0; int ans = 0; while(1) { ans += DP[bucket[currbucket][currpos]]; currpos = G[bucket[currbucket][currpos]]; int ansj = -1; int R = V[bucket[currbucket][currpos]] + L; for(int j = currbucket + 1; j <= lastbucket; j++) { if(V[bucket[j].back()] <= R) continue; else { ansj = j; break; } } if(ansj == -1) break; else { currbucket = ansj; int l = 0, r = bucket[currbucket].size() - 1; int ansj2 = -1; while(l <= r) { int mid = (l + r) / 2; if(V[bucket[ansj][mid]] > R) { r = mid - 1; ansj2 = mid; } else l = mid + 1; } currpos = ansj2; } } return ans; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 3 ms | 376 KB | Output is correct |
5 | Correct | 3 ms | 376 KB | Output is correct |
6 | Correct | 3 ms | 376 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 3 ms | 376 KB | Output is correct |
5 | Correct | 3 ms | 376 KB | Output is correct |
6 | Correct | 3 ms | 376 KB | Output is correct |
7 | Correct | 1177 ms | 1520 KB | Output is correct |
8 | Correct | 1219 ms | 1528 KB | Output is correct |
9 | Correct | 1364 ms | 2520 KB | Output is correct |
10 | Correct | 875 ms | 2676 KB | Output is correct |
11 | Correct | 815 ms | 2416 KB | Output is correct |
12 | Correct | 1852 ms | 2584 KB | Output is correct |
13 | Correct | 887 ms | 2520 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 3 ms | 376 KB | Output is correct |
5 | Correct | 3 ms | 376 KB | Output is correct |
6 | Correct | 3 ms | 376 KB | Output is correct |
7 | Correct | 1177 ms | 1520 KB | Output is correct |
8 | Correct | 1219 ms | 1528 KB | Output is correct |
9 | Correct | 1364 ms | 2520 KB | Output is correct |
10 | Correct | 875 ms | 2676 KB | Output is correct |
11 | Correct | 815 ms | 2416 KB | Output is correct |
12 | Correct | 1852 ms | 2584 KB | Output is correct |
13 | Correct | 887 ms | 2520 KB | Output is correct |
14 | Correct | 1426 ms | 1928 KB | Output is correct |
15 | Correct | 1778 ms | 1812 KB | Output is correct |
16 | Correct | 3069 ms | 2880 KB | Output is correct |
17 | Correct | 3084 ms | 3440 KB | Output is correct |
18 | Correct | 3173 ms | 3312 KB | Output is correct |
19 | Correct | 1813 ms | 3284 KB | Output is correct |
20 | Correct | 3132 ms | 3376 KB | Output is correct |
21 | Correct | 2925 ms | 3440 KB | Output is correct |
22 | Correct | 1672 ms | 3312 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 3 ms | 376 KB | Output is correct |
5 | Correct | 3 ms | 376 KB | Output is correct |
6 | Correct | 3 ms | 376 KB | Output is correct |
7 | Correct | 1177 ms | 1520 KB | Output is correct |
8 | Correct | 1219 ms | 1528 KB | Output is correct |
9 | Correct | 1364 ms | 2520 KB | Output is correct |
10 | Correct | 875 ms | 2676 KB | Output is correct |
11 | Correct | 815 ms | 2416 KB | Output is correct |
12 | Correct | 1852 ms | 2584 KB | Output is correct |
13 | Correct | 887 ms | 2520 KB | Output is correct |
14 | Correct | 1426 ms | 1928 KB | Output is correct |
15 | Correct | 1778 ms | 1812 KB | Output is correct |
16 | Correct | 3069 ms | 2880 KB | Output is correct |
17 | Correct | 3084 ms | 3440 KB | Output is correct |
18 | Correct | 3173 ms | 3312 KB | Output is correct |
19 | Correct | 1813 ms | 3284 KB | Output is correct |
20 | Correct | 3132 ms | 3376 KB | Output is correct |
21 | Correct | 2925 ms | 3440 KB | Output is correct |
22 | Correct | 1672 ms | 3312 KB | Output is correct |
23 | Correct | 6748 ms | 6764 KB | Output is correct |
24 | Correct | 7156 ms | 6632 KB | Output is correct |
25 | Correct | 6186 ms | 6736 KB | Output is correct |
26 | Correct | 5792 ms | 6636 KB | Output is correct |
27 | Correct | 6432 ms | 6632 KB | Output is correct |
28 | Correct | 5255 ms | 2424 KB | Output is correct |
29 | Correct | 5145 ms | 2336 KB | Output is correct |
30 | Correct | 5219 ms | 2396 KB | Output is correct |
31 | Correct | 5141 ms | 2348 KB | Output is correct |
32 | Correct | 5041 ms | 6756 KB | Output is correct |
33 | Correct | 4072 ms | 6772 KB | Output is correct |
34 | Correct | 5610 ms | 6612 KB | Output is correct |
35 | Correct | 4602 ms | 7848 KB | Output is correct |
36 | Correct | 4534 ms | 6792 KB | Output is correct |
37 | Correct | 8303 ms | 6776 KB | Output is correct |
38 | Correct | 5802 ms | 6692 KB | Output is correct |
39 | Correct | 6112 ms | 6688 KB | Output is correct |
40 | Correct | 5817 ms | 6760 KB | Output is correct |
41 | Execution timed out | 9050 ms | 6712 KB | Time limit exceeded |
42 | Halted | 0 ms | 0 KB | - |