Submission #413480

# Submission time Handle Problem Language Result Execution time Memory
413480 2021-05-28T19:13:29 Z JerryLiu06 Regions (IOI09_regions) Java 11
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using db = long double;
using str = string;

using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;

using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;

#define mp make_pair
#define f first
#define s second

#define sz(x) (int)(x).size()
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define sor(x) sort(all(x))
#define ft front()
#define bk back()
#define pb push_back
#define pf push_front

#define lb lower_bound
#define ub upper_bound

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define R0F(i, a) ROF(i, 0, a)
#define EACH(a, x) for (auto& a : x)

const int MOD = 1e9 + 7;
const int MXN = 2e5 + 10;
const int MXR = 25010;
const ll INF = 1e18;

const int BLOCK = 450;

int N, R, Q; vi adj[MXN]; int L[MXN]; // L[i] = Region of i

int timer = 1, in[MXN], out[MXN]; vi S[MXR]; // Sorted list of {in, out} for each region

vi large; int up[BLOCK][MXR], down[BLOCK][MXR];

int ind[MXN];

// Preorder Traversal ~ O(N)

void DFS(int X, int P) {
    in[X] = timer++; S[L[X]].pb(X);
    
    EACH(Y, adj[X]) if (Y != P) DFS(Y, X); out[X] = timer - 1;
}
bool isAnc(int A, int B) { return in[A] <= in[B] && out[B] <= out[A]; }

// Get the answer when queried (A, B) ~ O(N)

int genAns(int A, int B) {
    int ans = 0; int L = 0, R = 0; int last = 0; deque<int> anc;

    while (L < sz(S[A]) || R < sz(S[B])) {
        if (L < sz(S[A]) && (R >= sz(S[B]) || in[S[A][L]] < in[S[B][R]])) {
            while (sz(anc) && !isAnc(anc.bk, S[A][L])) anc.pop_back(); anc.pb(S[A][L++]);
        }
        else { while (sz(anc) && !isAnc(anc.bk, S[B][R])) anc.pop_back(); ans += sz(anc); R++; }
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);

    cin >> N >> R >> Q >> L[1];

    FOR(i, 2, N + 1) { int A; cin >> A >> L[i]; adj[A].pb(i), adj[i].pb(A); }

    DFS(1, 0); 
    
    int cur = 0; FOR(i, 1, R + 1) if (sz(S[i]) >= BLOCK) large.pb(i), ind[i] = cur++;

    F0R(i, sz(large)) {
        FOR(j, 1, R + 1) { 
            up[i][j] = genAns(large[i], j); 
            down[i][j] = genAns(j, large[i]); 
        }
    }
    F0R(i, Q) {
        int A, B; cin >> A>> B; 
        
        if (sz(S[A]) >= BLOCK) cout << up[ind[A]][B] << "\n";
        
        else if (sz(S[B]) >= BLOCK) cout << down[ind[B]][A] << "\n";
        
        else cout << genAns(A, B) << "\n";
    }
}

Compilation message

regions.java:1: error: illegal character: '#'
#include <bits/stdc++.h>
^
regions.java:1: error: class, interface, or enum expected
#include <bits/stdc++.h>
         ^
regions.java:5: error: class, interface, or enum expected
using ll = long long;
^
regions.java:6: error: class, interface, or enum expected
using db = long double;
^
regions.java:7: error: class, interface, or enum expected
using str = string;
^
regions.java:9: error: class, interface, or enum expected
using pi = pair<int, int>;
^
regions.java:10: error: class, interface, or enum expected
using pl = pair<ll, ll>;
^
regions.java:11: error: class, interface, or enum expected
using pd = pair<db, db>;
^
regions.java:13: error: class, interface, or enum expected
using vi = vector<int>;
^
regions.java:14: error: class, interface, or enum expected
using vb = vector<bool>;
^
regions.java:15: error: class, interface, or enum expected
using vl = vector<ll>;
^
regions.java:16: error: class, interface, or enum expected
using vd = vector<db>;
^
regions.java:17: error: class, interface, or enum expected
using vs = vector<str>;
^
regions.java:18: error: class, interface, or enum expected
using vpi = vector<pi>;
^
regions.java:19: error: class, interface, or enum expected
using vpl = vector<pl>;
^
regions.java:20: error: class, interface, or enum expected
using vpd = vector<pd>;
^
regions.java:22: error: illegal character: '#'
#define mp make_pair
^
regions.java:22: error: class, interface, or enum expected
#define mp make_pair
        ^
regions.java:23: error: illegal character: '#'
#define f first
^
regions.java:24: error: illegal character: '#'
#define s second
^
regions.java:26: error: illegal character: '#'
#define sz(x) (int)(x).size()
^
regions.java:27: error: illegal character: '#'
#define bg(x) begin(x)
^
regions.java:28: error: illegal character: '#'
#define all(x) bg(x), end(x)
^
regions.java:29: error: illegal character: '#'
#define sor(x) sort(all(x))
^
regions.java:30: error: illegal character: '#'
#define ft front()
^
regions.java:31: error: illegal character: '#'
#define bk back()
^
regions.java:32: error: illegal character: '#'
#define pb push_back
^
regions.java:33: error: illegal character: '#'
#define pf push_front
^
regions.java:35: error: illegal character: '#'
#define lb lower_bound
^
regions.java:36: error: illegal character: '#'
#define ub upper_bound
^
regions.java:38: error: illegal character: '#'
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
^
regions.java:38: error: class, interface, or enum expected
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
                                       ^
regions.java:38: error: class, interface, or enum expected
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
                                                ^
regions.java:39: error: illegal character: '#'
#define F0R(i, a) FOR(i, 0, a)
^
regions.java:40: error: illegal character: '#'
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--)
^
regions.java:40: error: class, interface, or enum expected
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--)
                                           ^
regions.java:40: error: class, interface, or enum expected
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--)
                                                     ^
regions.java:41: error: illegal character: '#'
#define R0F(i, a) ROF(i, 0, a)
^
regions.java:42: error: illegal character: '#'
#define EACH(a, x) for (auto& a : x)
^
regions.java:45: error: class, interface, or enum expected
const int MXN = 2e5 + 10;
^
regions.java:46: error: class, interface, or enum expected
const int MXR = 25010;
^
regions.java:47: error: class, interface, or enum expected
const ll INF = 1e18;
^
regions.java:49: error: class, interface, or enum expected
const int BLOCK = 450;
^
regions.java:51: error: class, interface, or enum expected
int N, R, Q; vi adj[MXN]; int L[MXN]; // L[i] = Region of i
^
regions.java:51: error: class, interface, or enum expected
int N, R, Q; vi adj[MXN]; int L[MXN]; // L[i] = Region of i
             ^
regions.java:51: error: class, interface, or enum expected
int N, R, Q; vi adj[MXN]; int L[MXN]; // L[i] = Region of i
                          ^
regions.java:53: error: class, interface, or enum expected
int timer = 1, in[MXN], out[MXN]; vi S[MXR]; // Sorted list of {in, out} for each region
^
regions.java:53: error: class, interface, or enum expected
int timer = 1, in[MXN], out[MXN]; vi S[MXR]; // Sorted list of {in, out} for each region
                                  ^
regions.java:55: error: class, interface, or enum expected
vi large; int up[BLOCK][MXR], down[BLOCK][MXR];
^
regions.java:55: error: class, interface, or enum expected
vi large; int up[BLOCK][MXR], down[BLOCK][MXR];
          ^
regions.java:57: error: class, interface, or enum expected
int ind[MXN];
^
regions.java:61: error: class, interface, or enum expected
void DFS(int X, int P) {
^
regions.java:62: error: class, interface, or enum expected
    in[X] = timer++; S[L[X]].pb(X);
                     ^
regions.java:64: error: class, interface, or enum expected
    EACH(Y, adj[X]) if (Y != P) DFS(Y, X); out[X] = timer - 1;
    ^
regions.java:64: error: class, interface, or enum expected
    EACH(Y, adj[X]) if (Y != P) DFS(Y, X); out[X] = timer - 1;
                                           ^
regions.java:65: error: class, interface, or enum expected
}
^
regions.java:66: error: class, interface, or enum expected
bool isAnc(int A, int B) { return in[A] <= in[B] && out[B] <= out[A]; }
                                                                      ^
regions.java:71: error: class, interface, or enum expected
    int ans = 0; int L = 0, R = 0; int last = 0; deque<int> anc;
                 ^
regions.java:71: error: class, interface, or enum expected
    int ans = 0; int L = 0, R = 0; int last = 0; deque<int> anc;
                                   ^
regions.java:71: error: class, interface, or enum expected
    int ans = 0; int L = 0, R = 0; int last = 0; deque<int> anc;
                                                 ^
regions.java:73: error: class, interface, or enum expected
    while (L < sz(S[A]) || R < sz(S[B])) {
    ^
regions.java:75: error: class, interface, or enum expected
            while (sz(anc) && !isAnc(anc.bk, S[A][L])) anc.pop_back(); anc.pb(S[A][L++]);
                                                                       ^
regions.java:76: error: class, interface, or enum expected
        }
        ^
regions.java:77: error: class, interface, or enum expected
        else { while (sz(anc) && !isAnc(anc.bk, S[B][R])) anc.pop_back(); ans += sz(anc); R++; }
                                                                          ^
regions.java:77: error: class, interface, or enum expected
        else { while (sz(anc) && !isAnc(anc.bk, S[B][R])) anc.pop_back(); ans += sz(anc); R++; }
                                                                                          ^
regions.java:77: error: class, interface, or enum expected
        else { while (sz(anc) && !isAnc(anc.bk, S[B][R])) anc.pop_back(); ans += sz(anc); R++; }
                                                                                               ^
regions.java:80: error: class, interface, or enum expected
}
^
regions.java:83: error: class, interface, or enum expected
    ios_base::sync_with_stdio(false); cin.tie(0);
                                      ^
regions.java:85: error: class, interface, or enum expected
    cin >> N >> R >> Q >> L[1];
    ^
regions.java:87: error: class, interface, or enum expected
    FOR(i, 2, N + 1) { int A; cin >> A >> L[i]; adj[A].pb(i), adj[i].pb(A); }
    ^
regions.java:87: error: class, interface, or enum expected
    FOR(i, 2, N + 1) { int A; cin >> A >> L[i]; adj[A].pb(i), adj[i].pb(A); }
                              ^
regions.java:87: error: class, interface, or enum expected
    FOR(i, 2, N + 1) { int A; cin >> A >> L[i]; adj[A].pb(i), adj[i].pb(A); }
                                                ^
regions.java:87: error: class, interface, or enum expected
    FOR(i, 2, N + 1) { int A; cin >> A >> L[i]; adj[A].pb(i), adj[i].pb(A); }
                                                                            ^
regions.java:91: error: class, interface, or enum expected
    int cur = 0; FOR(i, 1, R + 1) if (sz(S[i]) >= BLOCK) large.pb(i), ind[i] = cur++;
    ^
regions.java:91: error: class, interface, or enum expected
    int cur = 0; FOR(i, 1, R + 1) if (sz(S[i]) >= BLOCK) large.pb(i), ind[i] = cur++;
                 ^
regions.java:93: error: class, interface, or enum expected
    F0R(i, sz(large)) {
    ^
regions.java:96: error: class, interface, or enum expected
            down[i][j] = genAns(j, large[i]); 
            ^
regions.java:97: error: class, interface, or enum expected
        }
        ^
regions.java:100: error: class, interface, or enum expected
        int A, B; cin >> A>> B; 
                  ^
regions.java:102: error: class, interface, or enum expected
        if (sz(S[A]) >= BLOCK) cout << up[ind[A]][B] << "\n";
        ^
regions.java:104: error: class, interface, or enum expected
        else if (sz(S[B]) >= BLOCK) cout << down[ind[B]][A] << "\n";
        ^
regions.java:106: error: class, interface, or enum expected
        else cout << genAns(A, B) << "\n";
        ^
regions.java:107: error: class, interface, or enum expected
    }
    ^
83 errors