제출 #413025

#제출 시각아이디문제언어결과실행 시간메모리
413025ja_kingy코끼리 (Dancing Elephants) (IOI11_elephants)C++14
26 / 100
24 ms1180 KiB
#include "elephants.h" #include <bits/stdc++.h> using namespace std; const int SQRT = 500, mxN = 150000; int n, x[mxN+1], l, req[mxN], nx[mxN], blk[mxN], ucnt; vector<int> blocks[SQRT]; void build_block(int b) { int ne = blocks[b].size(); for (int i = blocks[b].size(); i--;) { while (x[blocks[b][ne-1]] > x[blocks[b][i]] + l) ne--; req[blocks[b][i]] = ne == blocks[b].size() ? 1 : req[blocks[b][ne]] + 1; nx[blocks[b][i]] = ne == blocks[b].size() ? x[blocks[b][i]] + l + 1 : nx[blocks[b][ne]]; } } void rebuild() { for (int i = 0; i < (n+SQRT-1)/SQRT; ++i) { blocks[i].clear(); } vector<int> order(n); iota(order.begin(), order.end(), 0); sort(order.begin(), order.end(), [&](int a, int b){return x[a] < x[b];}); int b = 0; for (int i = 0; i < n; ++i) { blocks[b].push_back(order[i]); blk[order[i]] = b; if (blocks[b].size() == SQRT || i == n-1) { build_block(b); b++; } } } void init(int N, int L, int X[]) { n = N; l = L; copy(X, X+n, x); rebuild(); } int update(int i, int y) { ucnt++; if (ucnt == SQRT) { ucnt = 0; rebuild(); } blocks[blk[i]].erase(find(blocks[blk[i]].begin(), blocks[blk[i]].end(), i)); build_block(blk[i]); x[i] = y; for (int b = 0; b < (n+SQRT-1)/SQRT; ++b) { if (b == (n+SQRT-1)/SQRT-1 || blocks[b].size() && x[blocks[b].back()] >= y) { blk[i] = b; blocks[b].insert(lower_bound(blocks[b].begin(), blocks[b].end(), i, [&](int a, int b){return x[a] < x[b];}), i); build_block(b); break; } } int ans = 0; x[n] = 0; for (int b = 0; b < (n+SQRT-1)/SQRT; ++b) { auto it = lower_bound(blocks[b].begin(), blocks[b].end(), n, [&](int a, int b){return x[a] < x[b];}); if (it != blocks[b].end()) { ans += req[*it]; x[n+1] = nx[*it]; } } return ans; }

컴파일 시 표준 에러 (stderr) 메시지

elephants.cpp: In function 'void build_block(int)':
elephants.cpp:13:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |         req[blocks[b][i]] = ne == blocks[b].size() ? 1 : req[blocks[b][ne]] + 1;
      |                             ~~~^~~~~~~~~~~~~~~~~~~
elephants.cpp:14:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |         nx[blocks[b][i]] = ne == blocks[b].size() ? x[blocks[b][i]] + l + 1 : nx[blocks[b][ne]];
      |                            ~~~^~~~~~~~~~~~~~~~~~~
elephants.cpp: In function 'int update(int, int)':
elephants.cpp:53:56: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   53 |         if (b == (n+SQRT-1)/SQRT-1 || blocks[b].size() && x[blocks[b].back()] >= y) {
      |                                       ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...