답안 #749932

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
749932 2023-05-29T01:36:22 Z vjudge1 사육제 (CEOI14_carnival) C++17
0 / 100
1 ms 208 KB
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define len(x) ll(x.size())
#define eb emplace_back
#define PI acos(-1.0)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define BIT(x,i) (1&((x)>>(i)))
#define MASK(x) (1LL<<(x))
#define task "tnc"
typedef long long ll;
typedef long double ld;
const ll INF=1e18;
const int maxn=1e6+5;
const int mod=1e9+7;
const int mo=998244353;
using pi=pair<ll,ll>;
using vi=vector<ll>;
using pii=pair<pair<ll,ll>,ll>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n;
int ask(int l,int r){
	cout<<"? "<<l<<" "<<r<<endl;
	int x;
	cin>>x;
	return x;
}
signed main()
{
	cin.tie(0),cout.tie(0)->sync_with_stdio(0);
    //freopen(task".inp" , "r" , stdin);
    //freopen(task".out" , "w" , stdout);
    int n;
    cin>>n;
    int x=ask(1,n);
    if(x!=1){

        int d=ask(1,x);
        if(d==x){
            int l=1;
            int r=x-1;
            int ans;
            while(l<=r){
                int mid=(l+r)/2;
                if(ask(mid,x)==x){
                    ans=mid;
                    l=mid+1;
                }
                else{
                    r=mid-1;
                }
            }
            cout<<"! "<<ans<<endl;
            return 0;
        }
    }
    int l=x+1;
    int r=n;
    int ans;
    while(l<=r){
        int mid=(l+r)/2;
        if(ask(x,mid)==x){
            ans=mid;
            r=mid-1;
        }
        else{
            l=mid+1;
        }
    }
    cout<<"! "<<ans<<endl;

    return 0;
}


Compilation message

carnival.cpp: In function 'int main()':
carnival.cpp:80:17: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   80 |     cout<<"! "<<ans<<endl;
      |                 ^~~
carnival.cpp:63:25: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   63 |             cout<<"! "<<ans<<endl;
      |                         ^~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 208 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 208 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 208 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 208 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 208 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -