제출 #352349

#제출 시각아이디문제언어결과실행 시간메모리
352349hivakarami코끼리 (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 + 5; const int sq = 500; const ll mod = 1e9 + 7; const ll inf = 1e16; int n, len, q = 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) { //cout << "id : "<< id << endl; int m = v[id].size(); nx[id][m-1] = v[id][m-1] + len; dp[id][m-1] = 1; for(int i = m - 2; i >= 0; i--) { if(v[id][m-1] > v[id][i]+len) { auto it = upper_bound(v[id].begin(), v[id].end(), v[id][i]+len); int p = it - v[id].begin(); nx[id][i] = nx[id][p]; dp[id][i] = dp[id][p] + 1; } else { dp[id][i] = 1; nx[id][i] = v[id][i] + len; } } //for(int i = m-1; i >= 0; i--) //cout << nx[id][i] << ' ' << dp[id][i] << endl; } void build() { sort(x, x + n); n = unique(x, x+n) - x; for(int i = 0; i < sq; i++) v[i].clear(); int id = 0; for(int i = 0; i < n; i++) { v[id].push_back(x[i]); if(v[id].size() == sq) { bld(id); id++; } } if(v[id].size() != 0) bld(id); //cout << "////////" << endl; } void add(int k, bool b) { int id = 0; for(int i = 0; i < sq; i++) { if(v[i].size() != 0 && 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; for(int i = 0; i < sq; i++) { if(j < v[i].size()) ans += dp[i][j]; if(v[i+1].empty()) break; j = upper_bound(v[i+1].begin(), v[i+1].end(), nx[i][j]) - v[i+1].begin(); } 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:168:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  168 |   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...