This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define pb push_back
#define sz(x) (int)(x.size())
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define vi vector<int>
#define vp vector<pii>
#define vvi vector<vi>
#define ykh mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count())
#define __lg(x) 63-__builtin_clzll(x)
#define pow2(x) (1LL<<x)
void __print(int x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef local
void setio(){freopen("/Users/iantsai/Library/Mobile Documents/com~apple~CloudDocs/cpp/Empty.md","r",stdin);}
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
void setio(){}
#define debug(x...)
#endif
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
struct line{
int a,b;
int operator()(const int x)const{
return a*x+b;
}
};
bool check(line l1,line l2,line l3){
return (l3.b-l2.b)*(l1.a-l2.a)<=(l2.b-l1.b)*(l2.a-l3.a);
}
const int mxn=1e5+5;
int n,m,q;
pair<int,int>edge[mxn];
bool used[mxn];
int seg[2][mxn*4];
void build(int l,int r,int id){
if(l==r){
seg[0][id]=seg[1][id]=l;
return;
}
int mm=l+r>>1;
build(l,mm,id*2);
build(mm+1,r,id*2+1);
seg[0][id]=min(seg[0][id*2],seg[0][id*2+1]);
seg[1][id]=max(seg[1][id*2],seg[1][id*2+1]);
}
void modify(int l,int r,int id,int ql,int qr,int v,bool f){
if(qr<l or r<ql){
return;
}
if(ql<=l and r<=qr){
seg[f][id]=v;
return;
}
int mm=l+r>>1;
modify(l,mm,id*2,ql,qr,v,f);
modify(mm+1,r,id*2+1,ql,qr,v,f);
if(f==0){
seg[f][id]=min(seg[f][id*2],seg[f][id*2+1]);
}
else{
seg[f][id]=max(seg[f][id*2],seg[f][id*2+1]);
}
}
void modify(int l,int r,int v,bool f){
modify(1,n,1,l,r,v,f);
}
pii query(int l,int r,int id,int p){
if(l==r){
return make_pair(seg[0][id],seg[1][id]);
}
int mm=l+r>>1;
if(p<=mm){
return query(l,mm,id*2,p);
}
else{
return query(mm+1,r,id*2+1,p);
}
}
pii query(int p){
return query(1,n,1,p);
}
signed main(){
setio();
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
set<pii>st;
cin>>n>>m>>q;
for(int i=1;i<n;i++){
st.insert({i,i});
cin>>edge[i].F>>edge[i].S;
}
st.insert({n,n});
build(1,n,1);
for(int i=0;i<m;i++){
int x;
cin>>x;
auto [l,r]=edge[x];
if(used[x]){
auto it=st.lower_bound(make_pair(0,r));
auto [L,R]=*it;
st.erase(it);
st.insert({L,l});
st.insert({r,R});
}
else{
auto it=st.lower_bound(make_pair(0,l));
auto it2=next(it);
modify(it->F,it->S,it2->S,1);
modify(it2->F,it2->S,it->F,0);
int L=it->F;
int R=it2->S;
st.erase(it);
st.erase(it2);
st.insert({L,R});
}
debug(st);
used[x]=!used[x];
}
while(q--){
int x;
cin>>x;
auto [l,r]=query(x);
cout<<r-l+1<<'\n';
}
}
/*
input:
*/
Compilation message (stderr)
synchronization.cpp: In function 'void build(long long int, long long int, long long int)':
synchronization.cpp:64:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
64 | int mm=l+r>>1;
| ~^~
synchronization.cpp: In function 'void modify(long long int, long long int, long long int, long long int, long long int, long long int, bool)':
synchronization.cpp:78:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
78 | int mm=l+r>>1;
| ~^~
synchronization.cpp: In function 'std::pair<long long int, long long int> query(long long int, long long int, long long int, long long int)':
synchronization.cpp:95:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
95 | int mm=l+r>>1;
| ~^~
synchronization.cpp: In function 'int main()':
synchronization.cpp:121:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
121 | auto [l,r]=edge[x];
| ^
synchronization.cpp:124:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
124 | auto [L,R]=*it;
| ^
synchronization.cpp:146:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
146 | auto [l,r]=query(x);
| ^
synchronization.cpp: In function 'void setIO(std::string)':
synchronization.cpp:42:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
42 | freopen((s + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
synchronization.cpp:43:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
43 | freopen((s + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |