Submission #347830

#TimeUsernameProblemLanguageResultExecution timeMemory
347830saralPictionary (COCI18_pictionary)C++14
56 / 140
1597 ms33300 KiB
#include <bits/stdc++.h> using namespace std; #define lli long long int const int N = 100100; int t, n, m, Q; lli u[N], sol[N], pom2[N]; pair<lli, lli > q[N]; vector<lli>v; int ufind (int x) { if (u[x]==x) return x; u[x] = ufind(u[x]); return u[x]; } void umerge (int x, int y) { x = ufind(x); y = ufind(y); if (x==y) return; if (rand()%2) { u[x]=y; } else { u[y]=x; } return; } int br=0; void f (lli l, lli r, vector<lli>Qpos) {; /*cout << br << endl; br++;*/ //cout << "da\n"; //cout << l << " " << (l+r)/2 << " " << r << " " << Qpos.size() << endl; /*for (int i = 0; i < Qpos.size(); i++) { cout << Qpos[i] << " "; } cout << endl;*/ vector<lli>pom; for (int i = 1; i <= n; i++) pom.push_back(u[i]); if (l==r) { for (int i = 0; i < Qpos.size(); i++) { sol[Qpos[i]]=l; } return; } if (Qpos.empty()) return; int mid = (l+r)/2; for (int i = l; i <= mid; i++) { int curr = m-i+1, foll = curr*2; while (foll <= n) { umerge (curr, foll); foll+=curr; } } //for (int i = 1; i <= n; i++) cout << i << ": " << ufind(i) << ", " << pom[i] << endl; //system("pause"); vector<lli>left; vector<lli>right; for (int i = 0; i < Qpos.size(); i++) { int a1=q[Qpos[i]].first, a2=q[Qpos[i]].second; if (ufind(a1)==ufind(a2)) { left.push_back(Qpos[i]); } else { right.push_back(Qpos[i]); } } /*cout << "right:"; for (int i = 0; i < right.size(); i++) cout << right[i] << " "; cout << "\n"; cout << "idem desno: \n";*/ f (mid+1, r, right); for (int i = 0; i < pom.size(); i++) u[i+1]=pom[i]; //cout << "idem lijevo: \n"; f (l, mid, left); return; } void solve () { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m >> Q; for (int i = 1; i <= Q; i++) { cin >> q[i].first >> q[i].second; v.push_back(i); } for (int i = 1; i <= n; i++) { u[i]=i; } f (1, m, v); for (int i = 1; i <= Q; i++) cout << sol[i] << "\n"; return; } int main () { solve(); return 0; } /* 25 6 1 25 10 */

Compilation message (stderr)

pictionary.cpp: In function 'void f(long long int, long long int, std::vector<long long int>)':
pictionary.cpp:42:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |         for (int i = 0; i < Qpos.size(); i++) {
      |                         ~~^~~~~~~~~~~~~
pictionary.cpp:64:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |     for (int i = 0; i < Qpos.size(); i++) {
      |                     ~~^~~~~~~~~~~~~
pictionary.cpp:78:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |     for (int i = 0; i < pom.size(); i++) u[i+1]=pom[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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...