Submission #448402

# Submission time Handle Problem Language Result Execution time Memory
448402 2021-07-30T04:43:45 Z SirCovidThe19th Dancing Elephants (IOI11_elephants) C++14
26 / 100
39 ms 18872 KB
#include <bits/stdc++.h>
using namespace std; 

#define ar2 array<int, 2>
#define lb(v, x) lower_bound(v.begin(), v.end(), x)-v.begin()

const int mx = 1.5e5+5, sq = 544, mSQ = mx/sq+5;

int N, L, X[mx], R[mx], mxB, reset; vector<int> blk[mx]; vector<ar2> dp[mx]; map<int, int> mp;

void calc(int b){
    int sz = blk[b].size(); dp[b].clear(); dp[b].resize(sz);
    for (int i = sz-1, p = sz-1; i >= 0; i--){
        while (blk[b][p]-blk[b][i] > L) p--;
        dp[b][i] = (p == sz-1) ? ar2{1, blk[b][i]+L} : ar2{dp[b][p+1][0]+1, dp[b][p+1][1]};
    }
}
void upd(int x, bool ins){
    int b = 0; while (x > R[b]) b++;  
    int p = lb(blk[b], x);
    ins ? blk[b].insert(blk[b].begin()+p, x) : blk[b].erase(blk[b].begin()+p);
    calc(b);
}
void build(){
    multiset<int> pos; int b = 0; blk[0].clear();
    for (int i = 0; i < N; i++) pos.insert(X[i]);
    for (auto i : mp){
        if (blk[b].size() >= sq) blk[++b].clear();
        blk[b].push_back(i.first);
    }for (int i = 0; i <= mxB; i++) calc(i), R[i] = (i == mxB) ? 2e9 : blk[i+1][0];
}
int query(){ 
    int ans = 0;
    for (int b = 0, x = -1; b <= mxB; b++){
        int p = lb(blk[b], x+1);
        if (p != blk[b].size()) x = dp[b][p][1], ans += dp[b][p][0];
    }return ans;
}
void init(int n, int l, int x[]){
    N = n; L = l; mxB = (N-1)/sq;  
    for (int i = 0; i < n; i++) X[i] = x[i], mp[X[i]]++;
    build();
}
int update(int i, int y){
    if (++reset == sq) build(), reset = 0;
    mp[X[i]]--; 
    if (!mp[X[i]]) upd(X[i], 0), mp.erase(X[i]);
    if (!mp[y]) upd(y, 1);
    mp[y]++; 
    X[i] = y; return query();
}


 

Compilation message

elephants.cpp: In function 'int query()':
elephants.cpp:36:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         if (p != blk[b].size()) x = dp[b][p][1], ans += dp[b][p][0];
      |             ~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7372 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Correct 4 ms 7372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7372 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Correct 4 ms 7372 KB Output is correct
4 Correct 5 ms 7372 KB Output is correct
5 Correct 5 ms 7372 KB Output is correct
6 Correct 5 ms 7372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7372 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Correct 4 ms 7372 KB Output is correct
4 Correct 5 ms 7372 KB Output is correct
5 Correct 5 ms 7372 KB Output is correct
6 Correct 5 ms 7372 KB Output is correct
7 Runtime error 39 ms 18872 KB Execution killed with signal 11
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7372 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Correct 4 ms 7372 KB Output is correct
4 Correct 5 ms 7372 KB Output is correct
5 Correct 5 ms 7372 KB Output is correct
6 Correct 5 ms 7372 KB Output is correct
7 Runtime error 39 ms 18872 KB Execution killed with signal 11
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7372 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Correct 4 ms 7372 KB Output is correct
4 Correct 5 ms 7372 KB Output is correct
5 Correct 5 ms 7372 KB Output is correct
6 Correct 5 ms 7372 KB Output is correct
7 Runtime error 39 ms 18872 KB Execution killed with signal 11
8 Halted 0 ms 0 KB -