Submission #624075

# Submission time Handle Problem Language Result Execution time Memory
624075 2022-08-07T08:06:47 Z radal Library (JOI18_library) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include "library.h"
#pragma GCC target("sse,sse2,avx2")
#pragma GCC optimize("unroll-loops,O2")
#define rep(i,l,r) for (int i = l; i < r; i++)
#define repr(i,r,l) for (int i = r; i >= l; i--)
#define X first
#define Y second
#define all(x) (x).begin() , (x).end()
#define pb push_back
#define endl '\n'
#define debug(x) cerr << #x << " : " << x << endl;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pll;
constexpr int N = 1e3+10,mod = 998244353,inf = 1e9+10;
int moj[N][2];
void Solve(int n){
    if (n == 1){
        vector<int> ve;
        ve.pb(1);
        Answer(ve);
        return;
    }
    memset(moj,-1,sizeof moj);
    vector<int> ask;
    ask.resize(n);
    rep(i,1,n+1){
        if (moj[i][0] != -1 && moj[i][1] != -1) continue;
        if (moj[i][0] != -1){
            int v = moj[i][0];
            rep(j,0,v){
                if (j == i-1) continue;
                ask[j] = 1;
            }
            rep(j,v,n) ask[j] = 0;
            int x = Query(ask);
            ask[i-1] = 1;
            int y = Query(ask);
            if (y-x == -1){
                int l = 0,r = v-1,m;
                while (r-l > 1){
                    m = (l+r) >> 1;
                    rep(j,0,m){
                        if (j == i-1) continue;
                        ask[j] = 1;
                    }
                    rep(j,m,n) ask[j] = 0;
                    x = Query(ask);
                    ask[i-1] = 1;
                    y = Query(ask);
                    if (y-x > 0) l = m;
                    else r = m;
                }
                moj[i][1] = r;
                if (moj[r][0] == -1) moj[r][0] = i;
                else moj[r][1] = i;
                continue;
            }
            int l = v,r = n+1,m;
            while (r-l > 1){
                m = (l+r) >> 1;
                rep(j,0,m){
                    if (j == i-1) continue;
                    ask[j] = 1;
                }
                rep(j,m,n) ask[j] = 0;
                x = Query(ask);
                ask[i-1] = 1;
                y = Query(ask);
                if (y-x == 0) l = m;
                else r = m;
            }
            if (r == n+1) continue;
            moj[i][1] = r;
            if (moj[r][0] == -1) moj[r][0] = i;
            else moj[r][1] = i;
            continue;
        }
        int l = 0,r = n+1,m,r2 = n+1,x,y;
        while (r-l > 1){
            m = (l+r) >> 1;
            rep(j,0,m){
                if (j == i-1) continue;
                ask[j] = 1;
            }
            rep(j,m,n) ask[j] = 0;
            x = Query(ask);
            ask[i-1] = 1;
            y = Query(ask);
            if (y-x == 1) l = m;
            else{
                r = m;
                if (y-x == -1) r2 = m;
            }
        }
        moj[i][0] = r;
        if (moj[r][0] == -1) moj[r][0] = i;
        else moj[r][1] = i;
        l = r;
        r = r2;
        while (r-l > 1){ 
            m = (l+r) >> 1;
            rep(j,0,m){
                if (j == i-1) continue;
                ask[j] = 1;
            }
            rep(j,m,n) ask[j] = 0;
            x = Query(ask);
            ask[i-1] = 1;
            y = Query(ask);
            if (y-x == 0) l = m;
            else r = m;
        }
        if (r == n+1) continue;
        moj[i][1] = r;
        if (moj[r][0] == -1) moj[r][0] = i;
        else moj[r][1] = i;
    }
    vector<int> ans;
    int cur = 1,perv = -1;
    rep(i,1,n+1) if (moj[i][1] == -1) cur = i;
    while (cur > 0){
        ans.pb(cur);
        if (moj[cur][0] == perv){
            perv = cur;
            cur = moj[cur][1];
        }
        else{
            perv = cur;
            cur = moj[cur][0];
        }
    }
    Answer(ans);
}
#include <bits/stdc++.h>
#include "library.h"
#pragma GCC target("sse,sse2,avx2")
#pragma GCC optimize("unroll-loops,O2")
#define rep(i,l,r) for (int i = l; i < r; i++)
#define repr(i,r,l) for (int i = r; i >= l; i--)
#define X first
#define Y second
#define all(x) (x).begin() , (x).end()
#define pb push_back
#define endl '\n'
#define debug(x) cerr << #x << " : " << x << endl;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pll;
constexpr int N = 1e3+10,mod = 998244353,inf = 1e9+10;
int moj[N][2];
void Solve(int n){
    if (n == 1){
        vector<int> ve;
        ve.pb(1);
        Answer(ve);
        return;
    }
    memset(moj,-1,sizeof moj);
    vector<int> ask;
    ask.resize(n);
    rep(i,1,n+1){
        if (moj[i][0] != -1 && moj[i][1] != -1) continue;
        if (moj[i][0] != -1){
            int v = moj[i][0];
            rep(j,0,v){
                if (j == i-1) continue;
                ask[j] = 1;
            }
            rep(j,v,n) ask[j] = 0;
            int x = Query(ask);
            ask[i-1] = 1;
            int y = Query(ask);
            if (y-x == -1){
                int l = 0,r = v-1,m;
                while (r-l > 1){
                    m = (l+r) >> 1;
                    rep(j,0,m){
                        if (j == i-1) continue;
                        ask[j] = 1;
                    }
                    rep(j,m,n) ask[j] = 0;
                    x = Query(ask);
                    ask[i-1] = 1;
                    y = Query(ask);
                    if (y-x > 0) l = m;
                    else r = m;
                }
                moj[i][1] = r;
                if (moj[r][0] == -1) moj[r][0] = i;
                else moj[r][1] = i;
                continue;
            }
            int l = v,r = n+1,m;
            while (r-l > 1){
                m = (l+r) >> 1;
                rep(j,0,m){
                    if (j == i-1) continue;
                    ask[j] = 1;
                }
                rep(j,m,n) ask[j] = 0;
                x = Query(ask);
                ask[i-1] = 1;
                y = Query(ask);
                if (y-x == 0) l = m;
                else r = m;
            }
            if (r == n+1) continue;
            moj[i][1] = r;
            if (moj[r][0] == -1) moj[r][0] = i;
            else moj[r][1] = i;
            continue;
        }
        int l = 0,r = n+1,m,r2 = n+1,x,y;
        while (r-l > 1){
            m = (l+r) >> 1;
            rep(j,0,m){
                if (j == i-1) continue;
                ask[j] = 1;
            }
            rep(j,m,n) ask[j] = 0;
            x = Query(ask);
            ask[i-1] = 1;
            y = Query(ask);
            if (y-x == 1) l = m;
            else{
                r = m;
                if (y-x == -1) r2 = m;
            }
        }
        moj[i][0] = r;
        if (moj[r][0] == -1) moj[r][0] = i;
        else moj[r][1] = i;
        l = r;
        r = r2;
        while (r-l > 1){ 
            m = (l+r) >> 1;
            rep(j,0,m){
                if (j == i-1) continue;
                ask[j] = 1;
            }
            rep(j,m,n) ask[j] = 0;
            x = Query(ask);
            ask[i-1] = 1;
            y = Query(ask);
            if (y-x == 0) l = m;
            else r = m;
        }
        if (r == n+1) continue;
        moj[i][1] = r;
        if (moj[r][0] == -1) moj[r][0] = i;
        else moj[r][1] = i;
    }
    vector<int> ans;
    int cur = 1,perv = -1;
    rep(i,1,n+1) if (moj[i][1] == -1) cur = i;
    while (cur > 0){
        ans.pb(cur);
        if (moj[cur][0] == perv){
            perv = cur;
            cur = moj[cur][1];
        }
        else{
            perv = cur;
            cur = moj[cur][0];
        }
    }
    Answer(ans);
}

Compilation message

library.cpp:155:15: error: redefinition of 'constexpr const int N'
  155 | constexpr int N = 1e3+10,mod = 998244353,inf = 1e9+10;
      |               ^
library.cpp:18:15: note: 'constexpr const int N' previously defined here
   18 | constexpr int N = 1e3+10,mod = 998244353,inf = 1e9+10;
      |               ^
library.cpp:155:26: error: redefinition of 'constexpr const int mod'
  155 | constexpr int N = 1e3+10,mod = 998244353,inf = 1e9+10;
      |                          ^~~
library.cpp:18:26: note: 'constexpr const int mod' previously defined here
   18 | constexpr int N = 1e3+10,mod = 998244353,inf = 1e9+10;
      |                          ^~~
library.cpp:155:42: error: redefinition of 'constexpr const int inf'
  155 | constexpr int N = 1e3+10,mod = 998244353,inf = 1e9+10;
      |                                          ^~~
library.cpp:18:42: note: 'constexpr const int inf' previously defined here
   18 | constexpr int N = 1e3+10,mod = 998244353,inf = 1e9+10;
      |                                          ^~~
library.cpp:156:5: error: redefinition of 'int moj [1010][2]'
  156 | int moj[N][2];
      |     ^~~
library.cpp:19:5: note: 'int moj [1010][2]' previously declared here
   19 | int moj[N][2];
      |     ^~~