Submission #956915

# Submission time Handle Problem Language Result Execution time Memory
956915 2024-04-02T16:28:28 Z yeediot Synchronization (JOI13_synchronization) C++14
0 / 100
203 ms 21360 KB
#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 tag[2][mxn*4];
int seg[2][mxn*4];
void build(int l,int r,int id){
    tag[1][id]=-1e18;
    tag[0][id]=1e18;
    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 push(bool f,int id){
    if(f){
        chmax(seg[f][id*2],tag[f][id]);
        chmax(seg[f][id*2+1],tag[f][id]);
        chmax(tag[f][id*2],tag[f][id]);
        chmax(tag[f][id*2+1],tag[f][id]);
    }
    else{
        chmin(seg[f][id*2],tag[f][id]);
        chmin(seg[f][id*2+1],tag[f][id]);
        chmin(tag[f][id*2],tag[f][id]);
        chmin(tag[f][id*2+1],tag[f][id]);
    }
}
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){
        if(f){
            chmax(seg[f][id],v);
            chmax(tag[f][id],v);
        }
        else{
            chmin(seg[f][id],v);
            chmin(tag[f][id],v);
        }
        return;
    }
    int mm=l+r>>1;
    push(f,id);
    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){
    debug(l,r,v);
    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;
    push(0,id);
    push(1,id);
    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);
        debug(l,r);
        cout<<r-l+1<<'\n';
    }
}
 /*
 input:
 
 */















 

Compilation message

synchronization.cpp: In function 'void build(long long int, long long int, long long int)':
synchronization.cpp:67:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   67 |     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:102:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  102 |     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:121:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  121 |     int mm=l+r>>1;
      |            ~^~
synchronization.cpp: In function 'int main()':
synchronization.cpp:149:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  149 |         auto [l,r]=edge[x];
      |              ^
synchronization.cpp:152:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  152 |             auto [L,R]=*it;
      |                  ^
synchronization.cpp:174:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  174 |         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
1 Correct 1 ms 6492 KB Output is correct
2 Incorrect 1 ms 6492 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 140 ms 20600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 6492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 203 ms 21360 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 6488 KB Output isn't correct
2 Halted 0 ms 0 KB -