제출 #1211542

#제출 시각아이디문제언어결과실행 시간메모리
1211542irmuunThe Potion of Great Power (CEOI20_potion)C++20
21 / 100
1028 ms98644 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define ff first #define ss second #define all(s) s.begin(),s.end() #define rall(s) s.rbegin(),s.rend() const int maxn=1e4+5; namespace { int N,D,H[maxn]; int U,A[maxn],B[maxn]; set<int>g[maxn][105]; set<int>st[maxn]; set<int>s1,s2; int blk; } void init(int N, int D, int H[]) { ::N=N,::D=D; for(int i=0;i<N;i++){ ::H[i]=H[i]; } } void curseChanges(int U, int A[], int B[]) { ::U=U; for(int i=0;i<U;i++){ if(A[i]>B[i]) swap(A[i],B[i]); ::A[i]=A[i]; ::B[i]=B[i]; } blk=sqrt(U); for(int i=0;i<U;i++){ if(st[A[i]].count(B[i])){ st[A[i]].erase(B[i]); st[B[i]].erase(A[i]); } else{ st[A[i]].insert(B[i]); st[B[i]].insert(A[i]); } if((i+1)%blk==0){ int C=(i+1)/blk; for(int j=0;j<N;j++){ g[j][C]=st[j]; } } } } int question(int x, int y, int v) { int ans=1e9; s1=g[x][v/blk],s2=g[y][v/blk]; for(int d=v/blk*blk;d<v;d++){ if(A[d]==x){ if(s1.count(B[d])) s1.erase(B[d]); else s1.insert(B[d]); } if(B[d]==x){ if(s1.count(A[d])) s1.erase(A[d]); else s1.insert(A[d]); } if(A[d]==y){ if(s2.count(B[d])) s2.erase(B[d]); else s2.insert(B[d]); } if(B[d]==y){ if(s2.count(A[d])) s2.erase(A[d]); else s2.insert(A[d]); } } vector<int>h1,h2; for(auto z:s1){ h1.pb(H[z]); } for(auto z:s2){ h2.pb(H[z]); } sort(all(h1)),sort(all(h2)); int i=0,j=0; while(i<h1.size()&&j<h2.size()){ ans=min(ans,abs(h1[i]-h2[j])); if(h1[i]<=h2[j]) i++; else j++; } return ans; }
#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...