Submission #1113282

# Submission time Handle Problem Language Result Execution time Memory
1113282 2024-11-16T09:42:32 Z kiethm07 Wall (IOI14_wall) C++11
100 / 100
1397 ms 89024 KB
#include <bits/stdc++.h>
#include <wall.h>

#define pii pair<int,int>
#define pli pair<long long,pii>
#define fi first
#define se second

#define vi vector<int>
#define vii vector<pii>
#define all(x) x.begin(),x.end()

using namespace std;

typedef long long ll;
typedef long double ld;

const int inf = 1e9;
const ll linf = 1e16;
const double pi = acos(-1);

class IT{
private:
    vector<int> low, high;
public:
    IT (int n){
        low.resize(4 * n,0);
        high.resize(4 * n,inf);
    }
    void apply(int id,int x,int y){
        high[id] = min(high[id], y);
        high[id] = max(high[id], x);
        low[id] = max(low[id], x);
        low[id] = min(low[id], y);
    }
    void down(int id,int l,int r){
        if (l == r) return;
        apply(id * 2,low[id],high[id]);
        apply(id * 2 + 1,low[id],high[id]);
        low[id] = 0;
        high[id] = inf;
    }
    void update(int id,int l,int r,int u,int v,int f,int g){
        down(id,l,r);
        if (l > v || r < u) return;
        if (l >= u && r <= v){
            apply(id,f,g);
            down(id,l,r);
            return;
        }
        int mid = (l + r) / 2;
        update(id * 2,l,mid,u,v,f,g);
        update(id * 2 + 1,mid + 1,r,u,v,f,g);
//            cout << l << " " << r << " " << u << " " << v << " " << low[id] << " " << high[id] << "\n";

    }
    int query(int id,int l,int r,int i){
        down(id,l,r);
//        cout << l << " " << r << " " << low[id] << " " << high[id] << "\n";
        if (l > i || r < i) return -1;
        if (l == r){
            return min(low[id], high[id]);
        }
        int mid = (l + r) / 2;
        int q1 = query(id * 2,l,mid,i);
        int q2 = query(id * 2 + 1,mid + 1,r,i);
        if (q1 == -1) return q2;
        return q1;
    }
};

void buildWall(int n,int k,int op[],int left[],int right[],int height[],int finalHeight[]){
    IT t(n);
    for (int i = 0; i < k; i++){
        int l = left[i] + 1;
        int r = right[i] + 1;
//        cout << l << " " << r << " " << op[i] << " " << height[i] << "\n";
        if (op[i] == 1) t.update(1,1,n,l,r,height[i],inf);
        if (op[i] == 2) t.update(1,1,n,l,r,0,height[i]);
    }
    for (int i = 1; i <= n; i++){
        finalHeight[i - 1] = t.query(1,1,n,i);
//        cout << finalHeight[i - 1] << " ";
    }
}
//
//int main(){
//    #define TEXT "a"
//    cin.tie(0) -> sync_with_stdio(0);
//    if (fopen(TEXT".inp","r")){
//        freopen(TEXT".inp","r",stdin);
//        freopen(TEXT".out","w",stdout);
//    }
//    int n = 10, k = 6;
//    int op[k] = {1,2,2,1,1,2};
//    int left[k] = {1,4,3,0,2,6};
//    int right[k] = {8,9,6,5,2,7};
//    int height[k] = {4,1,5,3,5,0};
//    int finalHeight[n] = {};
//    buildWall(n,k,op,left,right,height,finalHeight);
//    return 0;
//}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 7 ms 848 KB Output is correct
5 Correct 7 ms 960 KB Output is correct
6 Correct 7 ms 848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 119 ms 8264 KB Output is correct
3 Correct 167 ms 4176 KB Output is correct
4 Correct 457 ms 11656 KB Output is correct
5 Correct 279 ms 11592 KB Output is correct
6 Correct 305 ms 11756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 336 KB Output is correct
3 Correct 3 ms 592 KB Output is correct
4 Correct 7 ms 900 KB Output is correct
5 Correct 6 ms 848 KB Output is correct
6 Correct 7 ms 848 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 120 ms 14048 KB Output is correct
9 Correct 151 ms 8064 KB Output is correct
10 Correct 488 ms 21264 KB Output is correct
11 Correct 314 ms 21744 KB Output is correct
12 Correct 309 ms 20240 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 98 ms 13996 KB Output is correct
15 Correct 28 ms 1872 KB Output is correct
16 Correct 446 ms 21160 KB Output is correct
17 Correct 278 ms 20672 KB Output is correct
18 Correct 280 ms 20816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 336 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
4 Correct 8 ms 712 KB Output is correct
5 Correct 10 ms 960 KB Output is correct
6 Correct 7 ms 1016 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 91 ms 13992 KB Output is correct
9 Correct 140 ms 8104 KB Output is correct
10 Correct 439 ms 21320 KB Output is correct
11 Correct 274 ms 21832 KB Output is correct
12 Correct 290 ms 18868 KB Output is correct
13 Correct 1 ms 436 KB Output is correct
14 Correct 114 ms 13980 KB Output is correct
15 Correct 31 ms 1872 KB Output is correct
16 Correct 504 ms 17924 KB Output is correct
17 Correct 294 ms 20588 KB Output is correct
18 Correct 301 ms 20636 KB Output is correct
19 Correct 1397 ms 88576 KB Output is correct
20 Correct 1371 ms 89008 KB Output is correct
21 Correct 1335 ms 89012 KB Output is correct
22 Correct 1249 ms 88904 KB Output is correct
23 Correct 1223 ms 89024 KB Output is correct
24 Correct 1269 ms 88904 KB Output is correct
25 Correct 1354 ms 89008 KB Output is correct
26 Correct 1303 ms 89020 KB Output is correct
27 Correct 1366 ms 88928 KB Output is correct
28 Correct 1336 ms 89000 KB Output is correct
29 Correct 1352 ms 87492 KB Output is correct
30 Correct 1304 ms 88904 KB Output is correct