답안 #732060

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
732060 2023-04-28T10:19:03 Z Trunkty RMQ (NOI17_rmq) C++14
100 / 100
215 ms 14568 KB
#include <bits/extc++.h>
using namespace std;
typedef long long ll;
#define int ll

int n,q;
vector<vector<int>> ranges[100005];

int segtree[400005],lazy[400005];

void pushdown(int node, int l, int r){
    segtree[node] += lazy[node];
    if(l!=r){
        lazy[node*2] += lazy[node];
        lazy[node*2+1] += lazy[node]; 
    }
    lazy[node] = 0;
}

void update(int node, int l, int r, int needl, int needr, int val){
    pushdown(node,l,r);
    if(l>needr or r<needl){
        return;
    }
    else if(l>=needl and r<=needr){
        lazy[node] += val;
        pushdown(node,l,r);
    }
    else{
        int mid = (l+r)/2;
        update(node*2,l,mid,needl,needr,val);
        update(node*2+1,mid+1,r,needl,needr,val);
        segtree[node] = min(segtree[node*2],segtree[node*2+1]);
    }
}

int pos; 

void walk(int node, int l, int r, int needl, int needr){
    pushdown(node,l,r);
    int mid = (l+r)/2;
    if(l>needr or r<needl){
        return;
    }
    else if(l>=needl and r<=needr){
        if(segtree[node]!=0){
            return;
        }
        if(l==r){
            pos = l;
        }
        else{
            pushdown(node*2,l,mid);
            pushdown(node*2+1,mid+1,r);
            if(segtree[node*2]==0){
                walk(node*2,l,mid,needl,needr);
            }
            else{
                walk(node*2+1,mid+1,r,needl,needr);
            }
        }
    }
    else{
        walk(node*2,l,mid,needl,needr);
        if(pos!=-1){
            return;
        }
        walk(node*2+1,mid+1,r,needl,needr);
    }
}

int ans[100005];

signed main(){
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
    cin >> n >> q;
    for(int i=1;i<=q;i++){
        int a,b,c;
        cin >> a >> b >> c;
        ranges[c].push_back({a,b});
        update(1,0,n-1,a,b,1);
    }
    for(int i=0;i<n;i++){
        int a=0,b=n-1;
        for(vector<int> j:ranges[i]){
            update(1,0,n-1,j[0],j[1],-1);
            a = max(a,j[0]);
            b = min(b,j[1]);
        }
        if(a>b){
            for(int j=1;j<=n;j++){
                cout << -1 << " ";
            }
            cout << "\n";
            return 0;
        }
        pos = -1;
        walk(1,0,n-1,a,b);
        if(pos==-1){
            for(int j=1;j<=n;j++){
                cout << -1 << " ";
            }
            cout << "\n";
            return 0;
        }
        ans[pos] = i;
        update(1,0,n-1,pos,pos,2e9);
    }
    for(int i=0;i<=n-1;i++){
        cout << ans[i] << " ";
    }
    cout << "\n";
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2656 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2660 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 1 ms 2656 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2656 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2660 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 1 ms 2656 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 3 ms 2644 KB Output is correct
13 Correct 3 ms 2772 KB Output is correct
14 Correct 3 ms 2644 KB Output is correct
15 Correct 3 ms 2644 KB Output is correct
16 Correct 3 ms 2772 KB Output is correct
17 Correct 3 ms 2772 KB Output is correct
18 Correct 3 ms 2644 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 2 ms 2772 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 2 ms 2644 KB Output is correct
24 Correct 2 ms 2772 KB Output is correct
25 Correct 3 ms 2644 KB Output is correct
26 Correct 2 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2656 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2660 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 1 ms 2656 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 3 ms 2644 KB Output is correct
13 Correct 3 ms 2772 KB Output is correct
14 Correct 3 ms 2644 KB Output is correct
15 Correct 3 ms 2644 KB Output is correct
16 Correct 3 ms 2772 KB Output is correct
17 Correct 3 ms 2772 KB Output is correct
18 Correct 3 ms 2644 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 2 ms 2772 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 2 ms 2644 KB Output is correct
24 Correct 2 ms 2772 KB Output is correct
25 Correct 3 ms 2644 KB Output is correct
26 Correct 2 ms 2652 KB Output is correct
27 Correct 212 ms 14568 KB Output is correct
28 Correct 186 ms 13556 KB Output is correct
29 Correct 148 ms 12264 KB Output is correct
30 Correct 215 ms 14200 KB Output is correct
31 Correct 163 ms 10892 KB Output is correct
32 Correct 181 ms 11832 KB Output is correct
33 Correct 43 ms 7832 KB Output is correct
34 Correct 28 ms 5496 KB Output is correct
35 Correct 70 ms 8512 KB Output is correct
36 Correct 90 ms 11208 KB Output is correct
37 Correct 135 ms 13284 KB Output is correct
38 Correct 8 ms 3412 KB Output is correct
39 Correct 120 ms 12288 KB Output is correct
40 Correct 2 ms 2644 KB Output is correct
41 Correct 2 ms 2644 KB Output is correct