Submission #767556

#TimeUsernameProblemLanguageResultExecution timeMemory
767556Essa2006Synchronization (JOI13_synchronization)C++14
0 / 100
132 ms14780 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define endl '\n' #define FF first #define SS second #define all(a) a.begin(), a.end() #define mod (ll)(1000000007) int n, q1, q2, m; vector<vector<int>>A; map<int, pair<int, int>>mp; void pre(){ A.clear(), mp.clear(); A.resize(n+1); m=n-1; } int main(){ ios_base::sync_with_stdio(0);cin.tie(0); cin>>n>>q1>>q2; pre(); int cnt=1; while(m--){ int u, v; cin>>u>>v; if(u>v) swap(u, v); A[u].push_back(v); A[v].push_back(u); mp[cnt++]={u, v}; } vector<int>Mnr(n+1), Mxr(n+1), Mnf(n+1), Mxf(n+1); for(int i=1;i<=n;i++){ Mnr[i]=Mxr[i]=Mnf[i]=Mxf[i]=i; } vector<bool>Active(n); while(q1--){ int id; cin>>id; int u=mp[id].FF, v=mp[id].SS; if(!Active[id]){ Mxr[Mnr[u]]=Mxr[v], Mnr[Mxr[v]]=Mnr[u]; Mxf[Mnr[u]]=Mxf[v], Mnf[Mxr[v]]=Mnf[u]; } else{ Mxr[Mnr[u]]=u, Mnr[Mxr[v]]=v; } Active[id]=!Active[id]; } for(int i=2;i<=n;i++){ Mxf[i]=max(Mxf[i], Mxf[i-1]); } for(int i=n-1;i>=1;i--){ Mnf[i]=min(Mnf[i], Mnf[i+1]); } while(q2--){ int x; cin>>x; cout<<Mxf[x]-Mnf[x]+1<<endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...