Submission #1297894

#TimeUsernameProblemLanguageResultExecution timeMemory
1297894iamsazidhMinerals (JOI19_minerals)C++20
40 / 100
60 ms74632 KiB



#include <bits/stdc++.h>
#include "minerals.h"
using namespace std;

typedef long long              ll;
typedef double                 dl;
typedef vector<int>            vi;
typedef vector<vector<int>>    vii;
typedef vector<ll>             vl;
typedef vector<bool>           vb;
typedef pair<int,int>         pii;
typedef pair<ll, ll>          pll;

#define ff                first
#define ss                second
#define all(a)            a.begin(),a.end()
#define gcd(a,b)          __gcd(a,b)
#define lcm(a,b)          (a*(b/gcd(a,b)))
#define file();           freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define spc               " "

#ifdef ONLINE_JUDGE
    #define debarr(array)
    #define deb(x)
#else
    #define debarr(array)  for(int w = 0; w < array.size(); w++) cerr << #array << "-" << w << " = " << array[w] << endl;
    #define deb(x)         cerr << #x << " = " << x << endl;

#endif


const double PI =         acos(-1);
const int MOD =           1000000007;
const int inf =           (2147483647);
const double EPS =        1e-6;
const int MAXN =          1e5+10;



void Solve(int N) {
    int n = N*2;
    vector<vii> arr((N+10)*20, vii(2));
    int idx = 0, pushTo = 0;
    int last = 0;
    for(int i = 1; i <= n; i++){
        int now = Query(i);
        if(now==last){
            arr[pushTo][1].push_back(i);
            Query(i);
        }else{
            arr[pushTo][0].push_back(i);
            last = now;
        }
    }
    pushTo++;
    // Took 2N operations
    // Two group differented
    stack<pii> order;
    order.push({0, 0});

    while(!order.empty()){
        vii x = arr[order.top().ff]; int gone = order.top().ss; order.pop();
        int sz = x[0].size();
        if(sz<=1) continue;
        int m = (sz)/2;
        for(int i = 0; i < m; i++) arr[pushTo][gone].push_back(x[gone][i]);
        for(int i = m; i < sz; i++) last = Query(x[gone][i]), arr[pushTo+1][gone].push_back(x[gone][i]);
        for(auto y: x[!gone]){
            int now = Query(y);
            if(now==last){
                arr[pushTo][!gone].push_back(y); Query(y);
            }else{
                arr[pushTo+1][!gone].push_back(y);
            }
            last = now;
        }
        order.push({pushTo, gone});
        order.push({pushTo+1, !gone});
        pushTo+=2;
    }


    for(auto x: arr){
        if(x[0].size()==1){
            Answer(x[0][0], x[1][0]);
        }
    }



    return;
}
#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...