Submission #448399

# Submission time Handle Problem Language Result Execution time Memory
448399 2021-07-30T04:29:08 Z SirCovidThe19th Dancing Elephants (IOI11_elephants) C++14
26 / 100
23 ms 2388 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], mxB, reset; vector<int> blk[mSQ]; vector<ar2> dp[mSQ]; 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][p]+L} : ar2{dp[b][p+1][0]+1, dp[b][p+1][1]};
    }
}
void upd(int x, bool ins){
    int b = 0; while (b < mxB and (x > blk[b+1][0])) 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);
}
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 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Incorrect 23 ms 2388 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Incorrect 23 ms 2388 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Incorrect 23 ms 2388 KB Output isn't correct
8 Halted 0 ms 0 KB -