Submission #347927

#TimeUsernameProblemLanguageResultExecution timeMemory
347927UncreativePictionary (COCI18_pictionary)C++14
140 / 140
596 ms15224 KiB
#include<iostream> #include<vector> #include<ctime> #include<random> #include<cmath> using namespace std; const int maxn = 100010; int par[maxn]; int Find(int x){ if (x != par[x]){ par[x] = Find(par[x]); } return par[x]; } void Union(int x, int y){ x = Find(x); y = Find(y); if (x == y){ return; } int c = (rand()%2); if (c == 0){ par[x] = y; } else { par[y] = x; } } int a[maxn]; int b[maxn]; int sol[maxn]; int lo[maxn]; int hi[maxn]; vector<int> md[maxn]; int main(){ srand(time(0)); ios_base::sync_with_stdio(false); cin.tie(0); int n, m, q; cin >> n >> m >> q; for (int i = 1; i <= q; i++){ cin >> a[i] >> b[i]; } for (int i = 1; i <= q; i++){ lo[i] = 1; hi[i] = m; md[(lo[i] + hi[i]) / 2].push_back(i); } int lg = (int)log2((double)m) + 3; for (int t = 0; t < lg; t++){ for (int i = 1; i <= n; i++){ par[i] = i; } for (int i = 1; i <= m; i++){ int mi = m - i + 1; for (int j = mi; j <= n - mi; j += mi){ Union(j, j + mi); } for (int j = 0; j < md[i].size(); j++){ int e = md[i][j]; if (Find(a[e]) == Find(b[e])){ sol[e] = i; hi[e] = i; } else { lo[e] = i + 1; } } md[i].clear(); } for (int i = 1; i <= q; i++){ md[(lo[i] + hi[i]) / 2].push_back(i); } } for (int i = 1; i <= q; i++){ cout << sol[i] << "\n"; } }

Compilation message (stderr)

pictionary.cpp: In function 'int main()':
pictionary.cpp:71:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |             for (int j = 0; j < md[i].size(); j++){
      |                             ~~^~~~~~~~~~~~~~
#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...