Submission #282419

# Submission time Handle Problem Language Result Execution time Memory
282419 2020-08-24T12:15:56 Z shayan_p Wall (IOI14_wall) C++17
100 / 100
1516 ms 111788 KB
#include<bits/stdc++.h>
#include "wall.h"

#define F first
#define S second
#define sz(s) (int(s.size()))
#define PB push_back
#define bit(n, k) (((n)>>(k))&1)

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;

const int maxn = 2e6 + 10, mod = 1e9 + 7, inf = 1e9 + 10;

int L[4 * maxn], R[4 * maxn], val[4 * maxn];

void merge(int a, int b){
    if(R[b] <= L[a])
	L[b] = R[b] = L[a];
    else if(R[a] <= L[b])
	L[b] = R[b] = R[a];
    else
	L[b] = max(L[b], L[a]), R[b] = min(R[b], R[a]);
}
void shift(int l, int r, int id){
    if(r-l == 1){
	if(val[id] < L[id])
	    val[id] = L[id];
	else if(R[id] < val[id])
	    val[id] = R[id];
	return;
    }
    merge(id, 2*id);
    merge(id, 2*id+1);
    L[id] = 0, R[id] = inf;
}
void add(int f, int s, int t, int x, int l = 0, int r = maxn, int id = 1){
    if(s <= l || r <= f)
	return;
    shift(l, r, id);
    if(f <= l && r <= s){
	if(t == 1)
	    L[id] = x, R[id] = inf;
	else
	    L[id] = 0, R[id] = x;
	return;
    }
    int mid = (l+r) >> 1;
    add(f, s, t, x, l, mid, 2*id);
    add(f, s, t, x, mid, r, 2*id+1);
}
int ask(int pos, int l = 0, int r = maxn, int id = 1){
    shift(l, r, id);
    if(r-l == 1)
	return val[id];
    int mid = (l+r) >> 1;
    if(pos < mid)
	return ask(pos, l, mid, 2*id);
    else
	return ask(pos, mid, r, 2*id+1);
}
void buildWall(int n, int q, int task[], int f[], int s[], int h[], int ans[]){
    fill(L, L + 4 * maxn, 0);
    fill(R, R + 4 * maxn, inf);
    for(int i = 0; i < q; i++)
	add(f[i], ++s[i], task[i], h[i]);
    for(int i = 0; i < n; i++)
	ans[i] = ask(i);
}

# Verdict Execution time Memory Grader output
1 Correct 42 ms 62968 KB Output is correct
2 Correct 42 ms 63096 KB Output is correct
3 Correct 41 ms 62968 KB Output is correct
4 Correct 50 ms 63352 KB Output is correct
5 Correct 46 ms 63352 KB Output is correct
6 Correct 46 ms 63224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 63096 KB Output is correct
2 Correct 355 ms 76628 KB Output is correct
3 Correct 277 ms 70264 KB Output is correct
4 Correct 724 ms 81784 KB Output is correct
5 Correct 493 ms 82832 KB Output is correct
6 Correct 461 ms 81196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 62972 KB Output is correct
2 Correct 41 ms 63104 KB Output is correct
3 Correct 39 ms 62968 KB Output is correct
4 Correct 48 ms 63352 KB Output is correct
5 Correct 47 ms 63224 KB Output is correct
6 Correct 45 ms 63224 KB Output is correct
7 Correct 38 ms 63000 KB Output is correct
8 Correct 354 ms 76664 KB Output is correct
9 Correct 291 ms 70264 KB Output is correct
10 Correct 748 ms 81784 KB Output is correct
11 Correct 470 ms 82812 KB Output is correct
12 Correct 464 ms 81144 KB Output is correct
13 Correct 37 ms 62968 KB Output is correct
14 Correct 375 ms 76772 KB Output is correct
15 Correct 86 ms 64248 KB Output is correct
16 Correct 902 ms 81912 KB Output is correct
17 Correct 479 ms 81400 KB Output is correct
18 Correct 469 ms 81272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 62968 KB Output is correct
2 Correct 41 ms 63096 KB Output is correct
3 Correct 40 ms 62968 KB Output is correct
4 Correct 49 ms 63264 KB Output is correct
5 Correct 47 ms 63224 KB Output is correct
6 Correct 46 ms 63244 KB Output is correct
7 Correct 38 ms 62968 KB Output is correct
8 Correct 377 ms 76664 KB Output is correct
9 Correct 288 ms 70264 KB Output is correct
10 Correct 774 ms 81660 KB Output is correct
11 Correct 468 ms 82932 KB Output is correct
12 Correct 474 ms 81148 KB Output is correct
13 Correct 36 ms 62968 KB Output is correct
14 Correct 358 ms 76664 KB Output is correct
15 Correct 87 ms 64376 KB Output is correct
16 Correct 910 ms 81908 KB Output is correct
17 Correct 469 ms 81388 KB Output is correct
18 Correct 469 ms 81448 KB Output is correct
19 Correct 1407 ms 111788 KB Output is correct
20 Correct 1376 ms 106052 KB Output is correct
21 Correct 1421 ms 111732 KB Output is correct
22 Correct 1516 ms 106220 KB Output is correct
23 Correct 1417 ms 106100 KB Output is correct
24 Correct 1425 ms 106092 KB Output is correct
25 Correct 1387 ms 106104 KB Output is correct
26 Correct 1408 ms 111712 KB Output is correct
27 Correct 1432 ms 111728 KB Output is correct
28 Correct 1376 ms 106248 KB Output is correct
29 Correct 1484 ms 106104 KB Output is correct
30 Correct 1412 ms 106208 KB Output is correct