Submission #986630

#TimeUsernameProblemLanguageResultExecution timeMemory
986630vjudge1The Potion of Great Power (CEOI20_potion)C++17
0 / 100
400 ms93392 KiB
#include<bits/stdc++.h> using namespace std; int SSZ=2; vector<pair<int,int>>C[100100]; map<int,set<int>> temps[100100]; set<int>cur[100100]; int h[100100]; void init(int N, int D, int H[]) { for(int i=0;i<N;i++) h[i]=H[i],temps[i][-1]; } void curseChanges(int U, int A[], int B[]) { for(int i=0;i<U;i++){ if(cur[A[i]].count(B[i])) cur[A[i]].erase(B[i]), cur[B[i]].erase(A[i]); else cur[A[i]].insert(B[i]), cur[B[i]].insert(A[i]); C[A[i]].push_back({i,B[i]}); C[B[i]].push_back({i,A[i]}); if(C[A[i]].size()%SSZ==0) temps[A[i]][i]=cur[A[i]]; if(C[B[i]].size()%SSZ==0) temps[B[i]][i]=cur[B[i]]; } for(auto&i:cur) i.clear(); } int calc(vector<int>A,vector<int>B){ int l=0,r=0,ans=1e9; while(l<A.size()&&r<B.size()){ ans=min(ans,abs(A[l]-B[r])); if(A[l]<B[r])l++; else r++; } return ans; } int question(int x, int y, int v) { vector<int>A,B; auto it=--temps[x].lower_bound(v); set<int>X=it->second; auto it2=upper_bound(C[x].begin(),C[x].end(),make_pair(it->first,0)); for(int i=it2-C[x].begin();i<C[x].size()&&C[x][i].first<v;i++) if(X.count(C[x][i].second)) X.erase(C[x][i].second); else X.insert(C[x][i].second); for(auto i:X)A.push_back(h[i]); it=--temps[y].upper_bound(v); X=it->second; it2=upper_bound(C[y].begin(),C[y].end(),make_pair(it->first,0)); for(int i=it2-C[y].begin();i<C[y].size()&&C[y][i].first<v;i++) if(X.count(C[y][i].second)) X.erase(C[y][i].second); else X.insert(C[y][i].second); for(auto i:X)B.push_back(h[i]); sort(A.begin(),A.end()); sort(B.begin(),B.end()); return calc(A,B); }

Compilation message (stderr)

potion.cpp: In function 'int calc(std::vector<int>, std::vector<int>)':
potion.cpp:31:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     while(l<A.size()&&r<B.size()){
      |           ~^~~~~~~~~
potion.cpp:31:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     while(l<A.size()&&r<B.size()){
      |                       ~^~~~~~~~~
potion.cpp: In function 'int question(int, int, int)':
potion.cpp:43:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     for(int i=it2-C[x].begin();i<C[x].size()&&C[x][i].first<v;i++)
      |                                ~^~~~~~~~~~~~
potion.cpp:51:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |     for(int i=it2-C[y].begin();i<C[y].size()&&C[y][i].first<v;i++)
      |                                ~^~~~~~~~~~~~
#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...