Submission #240619

#TimeUsernameProblemLanguageResultExecution timeMemory
240619vanicPictionary (COCI18_pictionary)C++14
56 / 140
1592 ms5888 KiB
#include <iostream> #include <math.h> #include <cstdio> #include <algorithm> #include <set> #include <vector> #include <stack> #include <queue> #include <map> #include <string.h> #include <array> #include <bitset> #include <time.h> #include <cstdlib> using namespace std; const int maxn=1e5+5; int n, m, q; vector < pair < int, int > > parent[maxn]; int binary(int x, int val){ int lo=0, hi=parent[x].size()-1, mid; while(lo<hi){ mid=(lo+hi)/2+1; if(parent[x][mid].first>val){ hi=mid-1; } else{ lo=mid; } } return lo; } int find(int x, int val){ int pos=binary(x, val); if(parent[x][pos].second==x){ return x; } return find(parent[x][pos].second, val); } void update(int x, int y, int val){ x=find(x, val); y=find(y, val); if(rand()%2){ swap(x, y); } parent[x].push_back({val, y}); } bool query(int x, int y, int val){ return find(x, val)==find(y, val); } int binary2(int x, int y){ int lo=1, hi=m, mid; while(lo<hi){ mid=(lo+hi)/2; if(!query(x, y, mid)){ lo=mid+1; } else{ hi=mid; } } return lo; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); srand(time(NULL)); cin >> n >> m >> q; for(int i=1; i<=n; i++){ parent[i].push_back({0, i}); } int br=1; for(int i=0; i<m; i++){ for(int j=(m-i)*2; j<=n; j+=m-i){ if(!query(j, j-m+i, br)){ // cout << "update " << j-m+i << " " << j << endl; update(j, j-m+i, br); } } br++; } /* for(int i=1; i<=n; i++){ cout << "parenti " << i << '\n'; for(int j=0; j<parent[i].size(); j++){ cout << parent[i][j].first << " " << parent[i][j].second << '\n'; } cout << '\n'; }*/ // cout << "proso" << endl; int a, b; for(int i=0; i<q; i++){ cin >> a >> b; cout << binary2(a, b) << '\n'; } return 0; }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...