QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#150693 | #6394. Turn on the Light | aesthetic# | WA | 2ms | 3676kb | C++14 | 2.9kb | 2023-08-26 01:07:50 | 2023-08-26 01:07:51 |
Judging History
answer
#include "bits/stdc++.h"
#define endl '\n'
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());
using namespace std;
// #define int long long
#define dbg_loc() cerr << __PRETTY_FUNCTION__ << " : " << __LINE__ << "\n"
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p){
return os << '(' << p.first << ", " << p.second << ')';
}
template<typename T_container,typename T=typename enable_if<!is_same<T_container,string>::value, typename T_container::value_type>::type>
ostream& operator<<(ostream &os, const T_container &v){
os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}';
}
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T){
cerr << ' ' << H;
dbg_out(T...);
}
#define LOCAL
#define LOCAL
#ifdef LOCAL
#define dbg(...) cerr<<"(" << #__VA_ARGS__<<"):" , dbg_out(__VA_ARGS__) , cerr << endl
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
ll mod = (1000000007LL);
inline ll Mod(ll a, ll b){return (a%b);}
inline ll poww(ll a, ll b){ll res = 1;while (b > 0){if(b & 1) res = (res * a)%mod;a = (a * a)%mod;b >>= 1;}return res;}
ll gcd (ll a, ll b) { while (b) { a %= b,swap(a, b);}return a;}
void read(vector<int> &w, int n){w.resize(n);for(int i = 0; i < n; i++) cin>>w[i];}
void print(vector<int> &w){for(int i =0; i < sz(w); i++){if(i == sz(w) - 1) cout<<w[i]<<"\n";else cout<<w[i]<<" ";}}
///CUIDADO COM MAXN
#define N 1000010 // 1E6
int n, k, v[N];
string s;
bool TESTE = false;
int POS_TESTE = 3546;
vi ligados;
int query(int x){
cout<<"? "<<x<<endl;
int delta;
if(!TESTE)
cin>>delta;
if(TESTE){
ligados.pb(x);
int l = 0,r=0;
for(auto w: ligados){
if(w < POS_TESTE){
l++;
}
if(w > POS_TESTE) r++;
}
return abs(l-r);
}
return delta;
}
int32_t main(){
// ios::sync_with_stdio(false); cin.tie(0);
cin>>n;
if(n <= 20){
int curr=-1e9;
for(int i = 1; i <= n; i++){
int delta = query(i);
if(delta == curr){
cout<<"! "<<i<<endl;
return 0;
}
curr=delta;
}
return 0;
}
int curr=-1e9;
for(int i = 1; i <= 20; i++){
int delta = query(i);
if(delta == curr){
cout<<"! "<<i<<endl;
return 0;
}
curr=delta;
}
int ini = 21, fim = n, best;
for(int cnt = 1; cnt <= 20; cnt ++){
int mid = (ini + fim)/2;
int delta = query(mid);
if(delta == curr){
cout<<"! "<<mid<<"\n";
return 0;
}
if(delta < curr){ // mid ta a direita de opt
fim=mid-1;
}
else ini = mid + 1;
curr = delta;
}
cout<<"! "<<best<<endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3656kb
input:
3 1 2 2
output:
? 1 ? 2 ? 3 ! 3
result:
ok Correct position at 3
Test #2:
score: 0
Accepted
time: 1ms
memory: 3644kb
input:
10 1 2 3 4 5 6 7 8 8
output:
? 1 ? 2 ? 3 ? 4 ? 5 ? 6 ? 7 ? 8 ? 9 ! 9
result:
ok Correct position at 9
Test #3:
score: 0
Accepted
time: 0ms
memory: 3676kb
input:
9 1 2 3 4 5 6 7 7
output:
? 1 ? 2 ? 3 ? 4 ? 5 ? 6 ? 7 ? 8 ! 8
result:
ok Correct position at 8
Test #4:
score: 0
Accepted
time: 1ms
memory: 3656kb
input:
8 1 2 3 4 5 6 6
output:
? 1 ? 2 ? 3 ? 4 ? 5 ? 6 ? 7 ! 7
result:
ok Correct position at 7
Test #5:
score: 0
Accepted
time: 1ms
memory: 3660kb
input:
7 1 2 3 4 5 5
output:
? 1 ? 2 ? 3 ? 4 ? 5 ? 6 ! 6
result:
ok Correct position at 6
Test #6:
score: 0
Accepted
time: 1ms
memory: 3588kb
input:
6 1 2 3 4 5 5
output:
? 1 ? 2 ? 3 ? 4 ? 5 ? 6 ! 6
result:
ok Correct position at 6
Test #7:
score: 0
Accepted
time: 1ms
memory: 3592kb
input:
5 1 2 3 3
output:
? 1 ? 2 ? 3 ? 4 ! 4
result:
ok Correct position at 4
Test #8:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
4 1 2 3 3
output:
? 1 ? 2 ? 3 ? 4 ! 4
result:
ok Correct position at 4
Test #9:
score: 0
Accepted
time: 1ms
memory: 3656kb
input:
3 1 1
output:
? 1 ? 2 ! 2
result:
ok Correct position at 2
Test #10:
score: 0
Accepted
time: 1ms
memory: 3608kb
input:
2 1 1
output:
? 1 ? 2 ! 2
result:
ok Correct position at 2
Test #11:
score: -100
Wrong Answer
time: 1ms
memory: 3596kb
input:
1 0
output:
? 1
result:
wrong answer format Unexpected end of file - token expected