제출 #353830

#제출 시각아이디문제언어결과실행 시간메모리
353830hivakarami코끼리 (Dancing Elephants) (IOI11_elephants)C++14
10 / 100
1 ms364 KiB
#include "elephants.h" #include<bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; #define f first #define s second const int N = 1e5 + 100; const int sq = 500; const ll mod = 1e9 + 7; const ll inf = 1e16; int n, len, q = 0, sz = 0; //int x[N]; int *x; vector<int> v[sq], tmp; int nx[sq][N], dp[sq][N]; map<int, int> cnt; //* void init(int N, int L, int X[]) { n = N; len = L; x = X; for(int i = 0; i < n; i++) cnt[x[i]]++; } //*/ void bld(int id) { int m = v[id].size(); nx[id][m-1] = v[id][m-1] + len; dp[id][m-1] = 1; int pt = m; for(int i = m - 1; i >= 0; i--) { while(pt > 0 && v[id][pt-1] > v[id][i] + len) pt--; if(pt >= m) { dp[id][i] = 1; nx[id][i] = v[id][i] + len; } else { dp[id][i] = dp[id][pt] + 1; nx[id][i] = nx[id][pt]; } } } void build() { sort(x, x + n); n = unique(x, x+n) - x; for(int i = 0; i < sq; i++) v[i].clear(); sz = 0; for(int i = 0; i < n; i++) { v[sz].push_back(x[i]); if(v[sz].size() == sq+1) { bld(sz); sz++; } } if(v[sz].size() != 0) bld(sz++); //cout << "////////" << endl; } void add(int k, bool b) { int id = 0; for(int i = 0; i < sz; i++) { if(v[i][0] <= k) { id = i; break; } } //cout << k << ' ' << id << endl; //for(auto a : v[id]) //cout << a << ' '; //cout << endl; if(!b) { tmp = v[id]; v[id].clear(); for(auto y : tmp) { if(y != k) v[id].push_back(y); } } else { bool fl = false; tmp = v[id]; v[id].clear(); for(auto y : tmp) { if(y > k) { v[id].push_back(k); fl = true; } v[id].push_back(y); } if(!fl) v[id].push_back(k); } //for(auto y : v[id]) //cout << y << ' '; //cout << endl; bld(id); } int update(int i, int y) { if(q%sq == 0) build(); q++; cnt[x[i]]--; if(cnt[x[i]] == 0) add(x[i], 0); x[i] = y; if(cnt[x[i]] == 0) add(x[i], 1); cnt[y]++; int j = 0, ans = 0, t = -1; for(int i = 0; i < sq; i++) { if(v[i].empty()) break; j = upper_bound(v[i].begin(), v[i].end(), t) - v[i].begin(); if(j < v[i].size()) { ans += dp[i][j]; t = nx[i][j]; } } return ans; } /* int main() { cin >> n >> len; for(int i = 0; i < n; i++) { cin >> x[i]; cnt[x[i]]++; } int qu; cin >> qu; while(qu--) { int a, b; cin >> a >> b; cout << update(a, b) << endl; } return 0; } //*/

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

elephants.cpp: In function 'int update(int, int)':
elephants.cpp:164:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  164 |   if(j < v[i].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...
#Verdict Execution timeMemoryGrader output
Fetching results...