제출 #1128872

#제출 시각아이디문제언어결과실행 시간메모리
11288728pete8Gift Exchange (JOI24_ho_t4)C++20
100 / 100
1586 ms85272 KiB
#include<iostream> #include<stack> #include<map> #include<vector> #include<string> #include<unordered_map> #include <queue> #include<cstring> #include<limits.h> #include <cassert> #include <cstdint> #include<cmath> #include<set> #include<algorithm> #include <iomanip> #include<numeric> //gcd(a,b) #include<bitset> #define ll long long #define f first #define endl "\n" #define s second #define pii pair<int,int> #define ppii pair<int,pii> #define vi vector<int> #define pb push_back #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define F(n) for(int i=0;i<n;i++) #define lb lower_bound #define ub upper_bound #define fastio ios::sync_with_stdio(false);cin.tie(NULL); #pragma GCC optimize ("03,unroll-loops") using namespace std; //#define int long long #define double long double const int mod=1e9+7,mxn=5e5+5,lg=30,inf=1e9,minf=-1e9; int n,A[mxn+10],B[mxn+10],add[mxn+10],mode=0,base=minf,L[mxn+10],R[mxn+10],q,ans[mxn+10]; int comb(int a,int b){ if(mode)return min(a,b); return max(a,b); } struct seg{ int v[8*mxn+10],lazy[8*mxn+10]; void init(){for(int i=0;i<=8*n;i++)v[i]=lazy[i]=base;} void push(int l,int r,int pos){ v[pos]=comb(v[pos],lazy[pos]); if(l!=r){ lazy[pos*2]=comb(lazy[pos],lazy[pos*2]); lazy[pos*2+1]=comb(lazy[pos],lazy[pos*2+1]); } lazy[pos]=base; } void update(int l,int r,int pos,int ql,int qr,int val){ push(l,r,pos); if(l>qr||r<ql)return; if(ql<=l&&r<=qr){ lazy[pos]=val; push(l,r,pos); return; } int mid=l+(r-l)/2; update(l,mid,pos*2,ql,qr,val); update(mid+1,r,pos*2+1,ql,qr,val); v[pos]=comb(v[pos*2],v[pos*2+1]); } void updatepos(int l,int r,int pos,int qpos,int val){ push(l,r,pos); if(l==r)return void(v[pos]=val); int mid=l+(r-l)/2; if(qpos<=mid)updatepos(l,mid,pos*2,qpos,val); else updatepos(mid+1,r,pos*2+1,qpos,val); v[pos]=comb(v[pos*2],v[pos*2+1]); } int qry(int l,int r,int pos,int ql,int qr){ push(l,r,pos); if(l>qr||r<ql)return base; if(ql<=l&&r<=qr)return v[pos]; int mid=l+(r-l)/2; return comb(qry(l,mid,pos*2,ql,qr),qry(mid+1,r,pos*2+1,ql,qr)); } }t; //mode 0 = max //mode 1 =min vector<pii>ask[mxn+10]; vector<int>deact[mxn+10]; int32_t main(){ fastio cin>>n; for(int i=1;i<=n;i++)cin>>A[i]; for(int i=1;i<=n;i++)cin>>B[i]; t.init(); //get L for(int i=1;i<=n;i++){ L[i]=t.qry(1,2*n,1,B[i],A[i]); if(L[i]==minf)L[i]=0; L[i]++; t.update(1,2*n,1,B[i],A[i],i); } mode=1,base=inf; t.init(); for(int i=n;i>=1;i--){ R[i]=t.qry(1,2*n,1,B[i],A[i]); if(R[i]==inf)R[i]=n+1; R[i]--; deact[L[i]].pb(i); t.update(1,2*n,1,B[i],A[i],i); } cin>>q; for(int i=0;i<q;i++){ int l,r;cin>>l>>r; ask[l].pb({r,i}); } mode=0,base=minf; t.init(); for(int cl=n;cl>=1;cl--){ t.updatepos(1,n,1,cl,R[cl]); for(auto j:ask[cl])ans[j.s]=(t.qry(1,n,1,cl,j.f)<j.f); for(auto j:deact[cl])t.updatepos(1,n,1,j,minf); } for(int i=0;i<q;i++)cout<<((ans[i])?"Yes\n":"No\n"); } /* we can make a sub group/component (each range(B,A) intersects at least 1 range in the group) if we start at the min Ai we can try moving up to max Aj then we can start moving down from max Aj -> min Ai if we cant move Ai->Aj then its not a sub group if there exist a sub group with only 1 member then that member is forced to give the gift to himself which is not allow so the answer will be no we can then find L and R of each student where atleast 1 range will intersects them we can use sweep line + lazy seg for precompute L,R for qry sweep line L update at pos=i with val=R when Lcur<L we deactivate for qry just check if max(l,r)>r */
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...