Submission #986905

# Submission time Handle Problem Language Result Execution time Memory
986905 2024-05-21T14:25:43 Z Rifal Wall (IOI14_wall) C++14
100 / 100
483 ms 114772 KB
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;
const int N = 5e5 + 5;
const int M = 2e6 + 5;
pair<int,int> seg[N*4];
struct wall {
    int h, ty, ord;
};
pair<int,int> mer(pair<int,int> a, pair<int,int> b) {
        if(a.second < b.first) {
            return {b.first,b.first};
        }
        else if(a.first > b.second) {
            return {b.second,b.second};
        }
        else {
            return {max(a.first,b.first),min(a.second,b.second)};
        }

    return {0,INF};
}
void Build(int x, int l, int r) {
    if(l == r) {
        seg[x].first = 0;
        seg[x].second = INF;
    }
    else {
        int mid = (l+r)/2;
        Build(x*2,l,mid);
        Build(x*2+1,mid+1,r);
        seg[x].first = 0;
        seg[x].second = INF;
    }
}
void Update(int x, int l, int r, int pos, int ty, int val) {
    if(l == r) {
        if(val < 0) {
          //  cout << "aa" << endl;
            if(ty == 1) seg[x].first = 0;
            else seg[x].second = INF;
        }
        else {
          //  cout << "bb" << endl;
            if(ty == 1) seg[x].first = val;
            else seg[x].second = val;
        }
      //  cout << seg[x].first  << ' ' << seg[x].second << endl;
    }
    else {
        int mid = (l+r)/2;
        if(pos <= mid) Update(x*2,l,mid,pos,ty,val);
        else Update(x*2+1,mid+1,r,pos,ty,val);
        pair<int,int> pp = mer(seg[x*2],seg[x*2+1]);
    //    cout << l << ' ' << r << 'k' << endl;
      //  cout << pp.first << ' ' << pp.second << 'a' << endl;
        seg[x] = pp;
    }
}
vector<wall> v[M];
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]) {
    for(int i = 0; i < k; i++) {
        if(op[i] == 1) {
            wall cur;
            cur.h = height[i]+1;
            cur.ty = 1;
            cur.ord = i+1;
            v[left[i]].push_back(cur);
            cur.h *= -1;
            v[right[i]+1].push_back(cur);
        }
        else {
            wall cur;
            cur.h = height[i]+1;
            cur.ty = 2;
            cur.ord = i+1;
            v[left[i]].push_back(cur);
            cur.h *= -1;
            v[right[i]+1].push_back(cur);
        }
     }
     for(int i = 0; i < n; i++) finalHeight[i] = 1;
     Build(1,1,k+1);
     for(int i = 0; i < n; i++) {
        for(auto j : v[i]) {
           // cout << "JJJJJJJJJJJJJ" << endl;
           // cout << j.ord << ' ' << j.h << 'p' << endl;
            Update(1,1,k+1,j.ord,j.ty,j.h);
        }
        if(finalHeight[i] < seg[1].first) finalHeight[i] = seg[1].first;
        if(finalHeight[i] > seg[1].second) finalHeight[i] = seg[1].second;
     }
     for(int i = 0; i < n; i++) finalHeight[i]--;
}
# Verdict Execution time Memory Grader output
1 Correct 24 ms 47196 KB Output is correct
2 Correct 20 ms 47732 KB Output is correct
3 Correct 20 ms 47452 KB Output is correct
4 Correct 23 ms 47708 KB Output is correct
5 Correct 21 ms 47736 KB Output is correct
6 Correct 21 ms 47708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 47196 KB Output is correct
2 Correct 207 ms 75332 KB Output is correct
3 Correct 163 ms 62548 KB Output is correct
4 Correct 422 ms 83796 KB Output is correct
5 Correct 289 ms 81520 KB Output is correct
6 Correct 279 ms 80816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 47192 KB Output is correct
2 Correct 23 ms 47704 KB Output is correct
3 Correct 22 ms 47452 KB Output is correct
4 Correct 24 ms 47708 KB Output is correct
5 Correct 23 ms 47708 KB Output is correct
6 Correct 23 ms 47708 KB Output is correct
7 Correct 19 ms 47196 KB Output is correct
8 Correct 196 ms 75240 KB Output is correct
9 Correct 165 ms 62828 KB Output is correct
10 Correct 425 ms 83736 KB Output is correct
11 Correct 290 ms 81488 KB Output is correct
12 Correct 283 ms 80856 KB Output is correct
13 Correct 20 ms 47192 KB Output is correct
14 Correct 206 ms 75240 KB Output is correct
15 Correct 43 ms 49824 KB Output is correct
16 Correct 460 ms 84052 KB Output is correct
17 Correct 304 ms 80724 KB Output is correct
18 Correct 349 ms 79940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 47392 KB Output is correct
2 Correct 21 ms 47708 KB Output is correct
3 Correct 21 ms 47564 KB Output is correct
4 Correct 23 ms 47708 KB Output is correct
5 Correct 24 ms 47900 KB Output is correct
6 Correct 23 ms 47708 KB Output is correct
7 Correct 19 ms 47196 KB Output is correct
8 Correct 195 ms 75112 KB Output is correct
9 Correct 155 ms 62544 KB Output is correct
10 Correct 427 ms 83792 KB Output is correct
11 Correct 292 ms 81488 KB Output is correct
12 Correct 286 ms 80720 KB Output is correct
13 Correct 19 ms 47196 KB Output is correct
14 Correct 209 ms 75456 KB Output is correct
15 Correct 42 ms 49748 KB Output is correct
16 Correct 483 ms 84240 KB Output is correct
17 Correct 308 ms 80368 KB Output is correct
18 Correct 304 ms 79744 KB Output is correct
19 Correct 456 ms 106440 KB Output is correct
20 Correct 477 ms 112112 KB Output is correct
21 Correct 467 ms 114648 KB Output is correct
22 Correct 473 ms 112144 KB Output is correct
23 Correct 458 ms 112128 KB Output is correct
24 Correct 460 ms 112208 KB Output is correct
25 Correct 458 ms 112208 KB Output is correct
26 Correct 460 ms 114744 KB Output is correct
27 Correct 459 ms 114772 KB Output is correct
28 Correct 457 ms 112212 KB Output is correct
29 Correct 457 ms 112408 KB Output is correct
30 Correct 458 ms 112208 KB Output is correct