답안 #666754

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
666754 2022-11-29T14:10:27 Z 1bin 코끼리 (Dancing Elephants) (IOI11_elephants) C++17
100 / 100
3007 ms 13856 KB
#include <bits/stdc++.h>
#include "elephants.h"
 
using namespace std;
 
#define all(v) v.begin(), v.end()
typedef long long ll;
const int NMAX = 2e5 + 5;
const int b = 400;
int n, l, m, X[NMAX], q, cnt[b][b * 2 + 5], d[b][b * 2 + 5];
vector<int> v[b];
 
void init(int n_, int l_, int X_[]){
    n = n_; l = l_;
    for(int i = 0; i < n; i++) {
        X[i] = X_[i];
        v[i/b].emplace_back(X[i]);
    }
    return;
}
 
void go(int k){
    if(v[k].empty()) return;
    int sz = v[k].size();
    int ii = sz;
    
    for(int i = sz - 1; i >= 0; i--){
        auto&x = v[k][i];
        while(v[k][ii - 1] - x > l) ii--;
        if(ii == sz){
            cnt[k][i] = 1; 
            d[k][i] = x + l;
        }
        else {
            cnt[k][i] = cnt[k][ii] + 1;
            d[k][i] = d[k][ii];
        }
    }
    return;
}
 
void build(){
    vector<int> t;
    for(int i = 0; i < b; i++){
        for(auto& p : v[i]) t.emplace_back(p);
        v[i].clear();
    }
    for(int i = 0; i < n; i++) v[i / b].emplace_back(t[i]);
    for(int i = 0; i < b; i++) go(i);
    return;
}
 
int find(int x){
    int ret = 0;
    for(int i = 0; i < b; i++)
        if(v[i].size() && v[i][0] <= x) ret = i;
    return ret;
}
 
int update(int i, int y){
    if(q++ % b == 0) build();
    int k = find(X[i]);
    v[k].erase(lower_bound(all(v[k]), X[i]));
    go(k);
    
    X[i] = y;
    k = find(X[i]);
    auto it = lower_bound(all(v[k]), X[i]);
    if(it == v[k].end()) v[k].emplace_back(X[i]);
    else v[k].insert(it, X[i]);
    go(k);
 
    int ans = 0, e = -1;
    for(int i = 0; i < b; i++){
        auto it = upper_bound(all(v[i]), e);
        if(it != v[i].end()){
            int ix = it - v[i].begin();
            ans += cnt[i][ix]; e = d[i][ix];
        }
    }
    return ans;
}
 
/*
int main(void){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    cin >> n >> l >> m;
    for(int i = 0; i < n; i++) cin >> X[i];
    init(n, l, X);
    while(m--){
        int i, y;
        cin >> i >> y;
        cout << update(i, y) << '\n';
    }
    return 0;
}
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 255 ms 1392 KB Output is correct
8 Correct 269 ms 1628 KB Output is correct
9 Correct 268 ms 2828 KB Output is correct
10 Correct 274 ms 2772 KB Output is correct
11 Correct 294 ms 2864 KB Output is correct
12 Correct 486 ms 2880 KB Output is correct
13 Correct 283 ms 2968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 255 ms 1392 KB Output is correct
8 Correct 269 ms 1628 KB Output is correct
9 Correct 268 ms 2828 KB Output is correct
10 Correct 274 ms 2772 KB Output is correct
11 Correct 294 ms 2864 KB Output is correct
12 Correct 486 ms 2880 KB Output is correct
13 Correct 283 ms 2968 KB Output is correct
14 Correct 296 ms 1896 KB Output is correct
15 Correct 434 ms 3456 KB Output is correct
16 Correct 831 ms 5116 KB Output is correct
17 Correct 874 ms 6028 KB Output is correct
18 Correct 920 ms 5932 KB Output is correct
19 Correct 444 ms 6220 KB Output is correct
20 Correct 844 ms 6084 KB Output is correct
21 Correct 807 ms 6052 KB Output is correct
22 Correct 474 ms 5764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 255 ms 1392 KB Output is correct
8 Correct 269 ms 1628 KB Output is correct
9 Correct 268 ms 2828 KB Output is correct
10 Correct 274 ms 2772 KB Output is correct
11 Correct 294 ms 2864 KB Output is correct
12 Correct 486 ms 2880 KB Output is correct
13 Correct 283 ms 2968 KB Output is correct
14 Correct 296 ms 1896 KB Output is correct
15 Correct 434 ms 3456 KB Output is correct
16 Correct 831 ms 5116 KB Output is correct
17 Correct 874 ms 6028 KB Output is correct
18 Correct 920 ms 5932 KB Output is correct
19 Correct 444 ms 6220 KB Output is correct
20 Correct 844 ms 6084 KB Output is correct
21 Correct 807 ms 6052 KB Output is correct
22 Correct 474 ms 5764 KB Output is correct
23 Correct 2231 ms 13132 KB Output is correct
24 Correct 2541 ms 13280 KB Output is correct
25 Correct 1560 ms 13220 KB Output is correct
26 Correct 2139 ms 13308 KB Output is correct
27 Correct 2069 ms 13040 KB Output is correct
28 Correct 1039 ms 5208 KB Output is correct
29 Correct 1000 ms 5344 KB Output is correct
30 Correct 1027 ms 5208 KB Output is correct
31 Correct 992 ms 5240 KB Output is correct
32 Correct 1703 ms 12492 KB Output is correct
33 Correct 1587 ms 11880 KB Output is correct
34 Correct 1674 ms 12752 KB Output is correct
35 Correct 1534 ms 13160 KB Output is correct
36 Correct 1447 ms 12552 KB Output is correct
37 Correct 2291 ms 13856 KB Output is correct
38 Correct 1664 ms 11912 KB Output is correct
39 Correct 1542 ms 12848 KB Output is correct
40 Correct 1770 ms 11860 KB Output is correct
41 Correct 3002 ms 12568 KB Output is correct
42 Correct 3007 ms 12920 KB Output is correct