답안 #956917

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
956917 2024-04-02T16:32:37 Z yeediot 동기화 (JOI13_synchronization) C++14
0 / 100
337 ms 20848 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){
    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=prev(st.lower_bound(make_pair(r+1,0)));
            auto [L,R]=*it;
            st.erase(it);
            st.insert({L,l});
            st.insert({r,R});
        }
        else{
            auto it2=st.lower_bound(make_pair(l+1,0));
            auto it=prev(it2);
            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});
        }
        used[x]=!used[x];
        debug(l,r,st);
    }
    while(q--){
        int x;
        cin>>x;
        auto [l,r]=query(x);
        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:120:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  120 |     int mm=l+r>>1;
      |            ~^~
synchronization.cpp: In function 'int main()':
synchronization.cpp:148:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  148 |         auto [l,r]=edge[x];
      |              ^
synchronization.cpp:151:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  151 |             auto [L,R]=*it;
      |                  ^
synchronization.cpp:173:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  173 |         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);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Runtime error 7 ms 12940 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 162 ms 20820 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 6488 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 337 ms 20848 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 6492 KB Output isn't correct
2 Halted 0 ms 0 KB -