Submission #1095875

# Submission time Handle Problem Language Result Execution time Memory
1095875 2024-10-03T11:01:50 Z rayan_bd Klasika (COCI20_klasika) C++17
33 / 110
5000 ms 7672 KB
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")




#define getar(ar,n) for(ll i=0;i<n;++i) cin>>ar[i]
#define show(n) cout<<n<<'\n'
#define all(v) v.begin(), v.end()
#define br cout<<"\n"
#define pb push_back
#define nl '\n'
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define ret return
#define ll long long
#define ld long double
#define sza(x) ((int)x.size())

const int mxN = 2e5 + 500;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
const ld EPS = 1e-9;

ll parent[mxN];
vector<pair<ll,ll>> adj[mxN];
ll x=0,ans=0;

void from_u_to_v(ll u,ll v,ll par,ll xr){
    if(u==v){
        x=xr;
        return;
    }
    for(auto it:adj[u]){
        if(it.first^par){
            from_u_to_v(it.first,v,u,xr^it.second);
        }
    }
}


void get_maxima(ll u,ll xr){
    ans=max(ans,x^xr);
    for(auto it:adj[u]){
        if(it.first^parent[u]){
            get_maxima(it.first,xr^it.second);
        }
    }
}

void assign_parent(ll u=1,ll par=-1){
    parent[u]=par;
    for(auto it:adj[u]){
        if(it.first^par){
            assign_parent(it.first,u);
        }
    }
}

void solve() {
    ll n,u,v,tot=2;cin>>n;
    string str;
    for(ll i=0;i<n;++i){
        cin>>str>>u>>v;
        x=ans=0;
        if(str=="Add"){
            adj[u].pb({tot,v});
            adj[tot].pb({u,v});
            ++tot;
        }else if(str=="Query"){
            from_u_to_v(u,v,-1,0);
            assign_parent();
            get_maxima(v,0);
            show(ans);
        }
    }
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    solve();
    return 0;
}

Compilation message

klasika.cpp:25:39: warning: bad option '-fwhole-program' to pragma 'optimize' [-Wpragmas]
   25 | #pragma GCC optimize("-fwhole-program")
      |                                       ^
klasika.cpp:32:41: warning: bad option '-fstrict-overflow' to pragma 'optimize' [-Wpragmas]
   32 | #pragma GCC optimize("-fstrict-overflow")
      |                                         ^
klasika.cpp:34:41: warning: bad option '-fcse-skip-blocks' to pragma 'optimize' [-Wpragmas]
   34 | #pragma GCC optimize("-fcse-skip-blocks")
      |                                         ^
klasika.cpp:48:51: warning: bad option '-funsafe-loop-optimizations' to pragma 'optimize' [-Wpragmas]
   48 | #pragma GCC optimize("-funsafe-loop-optimizations")
      |                                                   ^
klasika.cpp:77:40: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
   77 | void from_u_to_v(ll u,ll v,ll par,ll xr){
      |                                        ^
klasika.cpp:77:40: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
klasika.cpp:77:40: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
klasika.cpp:77:40: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
klasika.cpp:90:27: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
   90 | void get_maxima(ll u,ll xr){
      |                           ^
klasika.cpp:90:27: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
klasika.cpp:90:27: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
klasika.cpp:90:27: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
klasika.cpp:99:36: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
   99 | void assign_parent(ll u=1,ll par=-1){
      |                                    ^
klasika.cpp:99:36: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
klasika.cpp:99:36: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
klasika.cpp:99:36: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
klasika.cpp:108:12: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
  108 | void solve() {
      |            ^
klasika.cpp:108:12: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
klasika.cpp:108:12: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
klasika.cpp:108:12: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
klasika.cpp:127:13: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
  127 | signed main() {
      |             ^
klasika.cpp:127:13: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
klasika.cpp:127:13: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
klasika.cpp:127:13: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5208 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4952 KB Output is correct
7 Correct 3 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 2 ms 5180 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 5132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5208 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4952 KB Output is correct
7 Correct 3 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 2 ms 5180 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 5132 KB Output is correct
13 Correct 7 ms 5208 KB Output is correct
14 Correct 7 ms 5212 KB Output is correct
15 Correct 9 ms 5212 KB Output is correct
16 Correct 6 ms 5260 KB Output is correct
17 Correct 5 ms 5212 KB Output is correct
18 Correct 7 ms 5212 KB Output is correct
19 Correct 8 ms 5212 KB Output is correct
20 Correct 6 ms 5212 KB Output is correct
21 Correct 5 ms 5212 KB Output is correct
22 Correct 7 ms 5240 KB Output is correct
23 Correct 8 ms 5212 KB Output is correct
24 Correct 6 ms 5212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5064 ms 7672 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5208 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4952 KB Output is correct
7 Correct 3 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 2 ms 5180 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 5132 KB Output is correct
13 Correct 7 ms 5208 KB Output is correct
14 Correct 7 ms 5212 KB Output is correct
15 Correct 9 ms 5212 KB Output is correct
16 Correct 6 ms 5260 KB Output is correct
17 Correct 5 ms 5212 KB Output is correct
18 Correct 7 ms 5212 KB Output is correct
19 Correct 8 ms 5212 KB Output is correct
20 Correct 6 ms 5212 KB Output is correct
21 Correct 5 ms 5212 KB Output is correct
22 Correct 7 ms 5240 KB Output is correct
23 Correct 8 ms 5212 KB Output is correct
24 Correct 6 ms 5212 KB Output is correct
25 Execution timed out 5064 ms 7672 KB Time limit exceeded
26 Halted 0 ms 0 KB -