Submission #53881303


Source Code Expand

#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<random>
#include<chrono>
#include<bitset>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair
#define ins insert
#define chkmn(x,y) (x)=min((x), (y))
#define chkmx(x,y) (x)=max((x), (y))
#define rep(i,a,b) for(int i=a;i<b;i++)

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) ((void)0)
#endif

using ll = long long;
using ull = unsigned long long ;
using ld = long double ;
using str = string;
//using ordered_set=tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update>;

const double PI=acos(-1);
const ll INF = 1LL<<62;
const ll MINF = -(1LL<<62);

template<typename T> T getint() {
    T val=0;
    char c;
    
    bool neg=false;
    while((c=gc()) && !(c>='0' && c<='9')) {
        neg|=c=='-';
    }

    do {
        val=(val*10)+c-'0';
    } while((c=gc()) && (c>='0' && c<='9'));

    return val*(neg?-1:1);
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int>(0, n-1)(rng)

int a[1<<18];
int n,l,r;
int ask(int i, int j) {
    cout<<"? "<<i<<" "<<j<<"\n"<<flush;
    int res=0;
    #ifdef LOCAL
    for(int k=(1<<i)*j;k<(1<<i)*(j+1);++k) res=(res+a[k])%100;
    #else
    cin>>res;
    if(res==-1) exit(0);
    #endif
    return res;
}

void answer(int ans) {
    cout<<"! "<<ans<<"\n";
    #ifdef LOCAL
    int res=0;
    for(int i=l;i<=r;++i) {
        (res+=a[i])%=100;
    }
    assert(res==ans);
    
    #endif
}
 

int main() {
    IO;
    cin>>n>>l>>r;
    #ifdef LOCAL
    for(int i=0;i<(1<<n);++i) a[i]=rand()%100;
    #endif
    int ans=0;
    auto calc=[](auto self, int L, int R, int i, int j) -> pair<int,int> {
        //~ LOG(L);
        //~ LOG(R);
        //~ LOG(i);
        //~ LOG(j);
        if(i<=L && R<=j) {
            return {1,0};
        }
        if(R<i || j<L) return {0,-1};
        int direct=self(self, L, (L+R)/2, i, j).xx+self(self, (L+R)/2+1, R, i, j).xx;
        int transp=1;
        transp+=self(self, L, (L+R)/2, L, i-1).xx;
        transp+=self(self, (L+R)/2+1, R, L, i-1).xx;
        transp+=self(self, L,(L+R)/2,j+1,R).xx;
        transp+=self(self, (L+R)/2+1,R,j+1,R).xx;
        
        if(direct<transp) return {direct, 0};
        else return {transp, 1};
    };
    auto solve=[&ans](auto self, auto calc, int L, int R, int i, int j, int n, int coeff) {
        if(i<=L && R<=j) {
            int res=ask(n, L/(1<<n));
            (ans+=coeff*res)%=100;
            return ;
        }
        if(R<i || j<L) return ;
        if(calc(calc, L, R, i, j).yy==0) {
            self(self, calc, L, (L+R)/2, i, j, n-1, coeff);
            self(self, calc, (L+R)/2+1, R, i, j, n-1, coeff);
        }else {
            int res=ask(n, L/(1<<n));
            (ans+=coeff*res)%=100;
            self(self, calc, L, (L+R)/2, L, i-1, n-1, -coeff);
            self(self, calc, (L+R)/2+1, R, j+1, R, n-1, -coeff);
        }
    };
    solve(solve, calc, 0,(1<<n)-1, l, r, n,1);
    if(ans<0) ans+=100;
    answer(ans);
    return 0;
}

Submission Info

Submission Time
Task E - Guess the Sum
User mraron
Language C++ 23 (gcc 12.2)
Score 500
Code Size 3845 Byte
Status AC
Exec Time 47 ms
Memory 5532 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 1
AC × 38
Set Name Test Cases
Sample 00_sample_00.txt
All 00_sample_00.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 3 ms 3704 KiB
01_random_00.txt AC 3 ms 3520 KiB
01_random_01.txt AC 3 ms 3512 KiB
01_random_02.txt AC 3 ms 3528 KiB
01_random_03.txt AC 3 ms 3564 KiB
01_random_04.txt AC 3 ms 3564 KiB
01_random_05.txt AC 3 ms 3720 KiB
01_random_06.txt AC 3 ms 3700 KiB
01_random_07.txt AC 3 ms 3704 KiB
01_random_08.txt AC 3 ms 3720 KiB
01_random_09.txt AC 3 ms 3528 KiB
01_random_10.txt AC 13 ms 3716 KiB
01_random_11.txt AC 4 ms 3716 KiB
01_random_12.txt AC 4 ms 3588 KiB
01_random_13.txt AC 12 ms 3868 KiB
01_random_14.txt AC 25 ms 4236 KiB
01_random_15.txt AC 39 ms 5268 KiB
01_random_16.txt AC 41 ms 5456 KiB
01_random_17.txt AC 38 ms 5400 KiB
01_random_18.txt AC 47 ms 5300 KiB
01_random_19.txt AC 39 ms 5252 KiB
01_random_20.txt AC 42 ms 5432 KiB
01_random_21.txt AC 45 ms 5296 KiB
01_random_22.txt AC 38 ms 5308 KiB
01_random_23.txt AC 35 ms 5312 KiB
01_random_24.txt AC 46 ms 5388 KiB
01_random_25.txt AC 46 ms 5276 KiB
01_random_26.txt AC 36 ms 5352 KiB
01_random_27.txt AC 36 ms 5532 KiB
01_random_28.txt AC 40 ms 5248 KiB
01_random_29.txt AC 45 ms 5304 KiB
01_random_30.txt AC 40 ms 5524 KiB
01_random_31.txt AC 30 ms 5368 KiB
01_random_32.txt AC 45 ms 5432 KiB
01_random_33.txt AC 40 ms 5408 KiB
01_random_34.txt AC 3 ms 3636 KiB
01_random_35.txt AC 3 ms 3696 KiB
01_random_36.txt AC 3 ms 3544 KiB