답안 #603555

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
603555 2022-07-24T08:05:32 Z 이동현(#8430) 동기화 (JOI13_synchronization) C++17
30 / 100
311 ms 39220 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int NS = (int)2e5 + 4;

int n, m, q;
vector<vector<int>> way[NS];
vector<int> a[NS];
int lst[NS];
vector<int> l[NS], r[NS];
int lans[NS], rans[NS];

int tr[NS * 4];

void push(int x, int s, int e, int ps, int pe, int val){
    if(pe < s || ps > e || ps > pe){
        return;
    }
    if(ps <= s && pe >= e){
        tr[x] = val;
        return;
    }
    if(tr[x] != -1){
        tr[x * 2] = tr[x * 2 + 1] = tr[x];
        tr[x] = -1;
    }
    int m = s + e >> 1;
    push(x * 2, s, m, ps, pe, val), push(x * 2 + 1, m + 1, e, ps, pe, val);
}

int get(int x, int s, int e, int pos){
    if(s == e){
        return tr[x];
    }
    if(tr[x] != -1){
        tr[x * 2] = tr[x * 2 + 1] = tr[x];
        tr[x] = -1;
    }
    int m = s + e >> 1;
    if(pos <= m) return get(x * 2, s, m, pos);
    return get(x * 2 + 1, m + 1, e, pos);
}

signed main(){
    memset(tr, -1, sizeof(tr));
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m >> q;
    for(int i = 1; i < n; ++i){
        a[i].resize(2);
        cin >> a[i][0] >> a[i][1];
        if(a[i][0] > a[i][1]){
            swap(a[i][0], a[i][1]);
        }
    }
    for(int i = 1; i <= m; ++i){
        int x; cin >> x;
        l[a[x][0]].push_back(i);
        r[a[x][1]].push_back(i);
    }
    for(int i = 1; i <= n; ++i){
        if((int)l[i].size() % 2) l[i].push_back(m);
        if((int)r[i].size() % 2) r[i].push_back(m);
    }

    push(1, 0, m, 0, m, 1);
    lans[1] = 1;
    for(int i = 2; i <= n; ++i){
        int lp = 0, lval = i;
        for(int j = 0; j < (int)r[i].size(); j += 2){
            push(1, 0, m, lp, r[i][j] - 1, lval);
            lp = r[i][j + 1] + 1;
            lval = get(1, 0, m, r[i][j + 1]);
        }
        push(1, 0, m, lp, m, lval);
        lans[i] = get(1, 0, m, m);
    }

    push(1, 0, m, 0, m, n);
    rans[n] = n;
    for(int i = n - 1; i >= 1; --i){
        int rp = 0, rval = i;
        for(int j = 0; j < (int)l[i].size(); j += 2){
            push(1, 0, m, rp, l[i][j] - 1, rval);
            rp = l[i][j + 1] + 1;
            rval = get(1, 0, m, l[i][j + 1]);
        }
        push(1, 0, m, rp, m, rval);
        rans[i] = get(1, 0, m, m);
    }

    while(q--){
        int x; cin >> x;
        cout << rans[x] - lans[x] + 1 << '\n';
        //cout << lans[x] << ' ' << rans[x] << endl;
    }
    return 0;
}

Compilation message

synchronization.cpp: In function 'void push(long long int, long long int, long long int, long long int, long long int, long long int)':
synchronization.cpp:28:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   28 |     int m = s + e >> 1;
      |             ~~^~~
synchronization.cpp: In function 'long long int get(long long int, long long int, long long int, long long int)':
synchronization.cpp:40:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   40 |     int m = s + e >> 1;
      |             ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 25300 KB Output is correct
2 Incorrect 15 ms 25300 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 107 ms 36780 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 25300 KB Output is correct
2 Correct 13 ms 25300 KB Output is correct
3 Correct 13 ms 25300 KB Output is correct
4 Correct 13 ms 25300 KB Output is correct
5 Correct 12 ms 25300 KB Output is correct
6 Correct 14 ms 25440 KB Output is correct
7 Correct 32 ms 26444 KB Output is correct
8 Correct 311 ms 37268 KB Output is correct
9 Correct 287 ms 37248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 280 ms 37240 KB Output is correct
2 Correct 95 ms 37164 KB Output is correct
3 Correct 111 ms 39220 KB Output is correct
4 Correct 112 ms 39136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 15 ms 25300 KB Output isn't correct
2 Halted 0 ms 0 KB -