Submission #347926

# Submission time Handle Problem Language Result Execution time Memory
347926 2021-01-13T19:22:04 Z Uncreative Pictionary (COCI18_pictionary) C++14
Compilation error
0 ms 0 KB
#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(false);
    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

pictionary.cpp: In function 'int main()':
pictionary.cpp:48:18: error: no matching function for call to 'std::basic_istream<char>::tie(bool)'
   48 |     cin.tie(false);
      |                  ^
In file included from /usr/include/c++/9/ios:44,
                 from /usr/include/c++/9/ostream:38,
                 from /usr/include/c++/9/iostream:39,
                 from pictionary.cpp:1:
/usr/include/c++/9/bits/basic_ios.h:295:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>* std::basic_ios<_CharT, _Traits>::tie() const [with _CharT = char; _Traits = std::char_traits<char>]'
  295 |       tie() const
      |       ^~~
/usr/include/c++/9/bits/basic_ios.h:295:7: note:   candidate expects 0 arguments, 1 provided
/usr/include/c++/9/bits/basic_ios.h:307:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>* std::basic_ios<_CharT, _Traits>::tie(std::basic_ostream<_CharT, _Traits>*) [with _CharT = char; _Traits = std::char_traits<char>]'
  307 |       tie(basic_ostream<_CharT, _Traits>* __tiestr)
      |       ^~~
/usr/include/c++/9/bits/basic_ios.h:307:43: note:   no known conversion for argument 1 from 'bool' to 'std::basic_ostream<char>*'
  307 |       tie(basic_ostream<_CharT, _Traits>* __tiestr)
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
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++){
      |                             ~~^~~~~~~~~~~~~~