Submission #901903

#TimeUsernameProblemLanguageResultExecution timeMemory
901903nguyentunglamDancing Elephants (IOI11_elephants)C++17
26 / 100
9063 ms58252 KiB
#include<bits/stdc++.h> #define fi first #define se second #define endl "\n" #define ii pair<int, int> using namespace std; const int N = 1e5 + 10, T = 1e3, _T = 1e9 / T; int n, l; int a[N], b[N]; vector<pair<int, int> > f[_T]; vector<int> arr[_T]; void add_block (int block, int x) { for(int i = 0; i < arr[block].size(); i++) if (arr[block][i] >= x) { arr[block].insert(arr[block].begin() + i, x); return; } arr[block].push_back(x); } void del_block (int block, int x) { for(int i = 0; i < arr[block].size(); i++) if (arr[block][i] == x) { arr[block].erase(arr[block].begin() + i); return; } } void update_block (int block) { f[block].resize(arr[block].size()); for(int i = arr[block].size() - 1, j = arr[block].size(); i >= 0; i--) { while (j > 0 && arr[block][j - 1] - l > arr[block][i]) { j--; } if (j == arr[block].size()) f[block][i] = make_pair(1, arr[block][i]); else f[block][i] = make_pair(f[block][j].first + 1, f[block][j].second); } } void init(int N, int L, int X[]) { n = N; l = L; for(int i = 0; i < n; i++) a[i] = X[i]; for(int i = 0; i < n; i++) arr[a[i] / T].push_back(a[i]); for(int block = 0; block < _T; block++) if (!arr[block].empty()) { sort(arr[block].begin(), arr[block].end()); update_block (block); } } int get () { int last = -1e9, ans = 0; for(int block = 0; block < _T; block++) if (!arr[block].empty()) { int x = upper_bound(arr[block].begin(), arr[block].end(), last + l) - arr[block].begin(); if (x < arr[block].size()) { ans += f[block][x].first; last = f[block][x].second; } } return ans; } int update(int i, int y) { del_block(a[i] / T, a[i]); update_block(a[i] / T); a[i] = y; add_block(a[i] / T, a[i]); update_block(a[i] / T); return get(); } #ifdef ngu int x[N]; int main() { freopen ("task.inp", "r", stdin); freopen ("task.out", "w", stdout); int n, l, m; cin >> n >> l >> m; for(int i = 0; i < n; i++) cin >> x[i]; init(n, l, x); while (m--) { int i, v; cin >> i >> v; cout << update(i, v) << endl; } } #endif // ngu

Compilation message (stderr)

elephants.cpp: In function 'void add_block(int, int)':
elephants.cpp:19:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |   for(int i = 0; i < arr[block].size(); i++) if (arr[block][i] >= x) {
      |                  ~~^~~~~~~~~~~~~~~~~~~
elephants.cpp: In function 'void del_block(int, int)':
elephants.cpp:27:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |   for(int i = 0; i < arr[block].size(); i++) if (arr[block][i] == x) {
      |                  ~~^~~~~~~~~~~~~~~~~~~
elephants.cpp: In function 'void update_block(int)':
elephants.cpp:39:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     if (j == arr[block].size()) f[block][i] = make_pair(1, arr[block][i]);
      |         ~~^~~~~~~~~~~~~~~~~~~~
elephants.cpp: In function 'int get()':
elephants.cpp:62:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     if (x < arr[block].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...