QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#876140#9734. Identify ChordLuluTL 12ms3584kbC++142.3kb2025-01-30 17:39:402025-01-30 17:39:41

Judging History

This is the latest submission verdict.

  • [2025-01-30 17:39:41]
  • Judged
  • Verdict: TL
  • Time: 12ms
  • Memory: 3584kb
  • [2025-01-30 17:39:40]
  • Submitted

answer

/*
Author:
Homework:QH01
Problem:identify
Time:2025 - 1 - 30
Calm down!
Think twice and type.
*/
#include<bits/stdc++.h>
#define REP(i,l,r) for(int i=(l);i<=(r);i++)
#define PER(i,r,l) for(int i=(r);i>=(l);i--)
#define pi pair<int,int>
#define mkp(x,y) make_pair(x,y)
#define fi first
#define se second
#define ll long long
#define lc tr[i].ch[0]
#define rc tr[i].ch[1]
#define Lc tr[j].ch[0]
#define Rc tr[j].ch[1]
#define lowbit(i) (i&(-i))
using namespace std;
inline int read(){
    int x=0,f=1;
    char c=getchar();
    while(!isdigit(c)){
        if(c=='-')f=-1;
        c=getchar();
    }
    while(isdigit(c)){
        x=(x<<3)+(x<<1)+c-'0';
        c=getchar();
    }
    return x*f;
}
void write(int x){
    if(x<0)putchar('-'),x=-x;
    if(x>9)write(x/10);
    putchar(x%10+'0');
}
int getrand(int mod){
    ll x=0;
    x<<=15,x+=rand();
    x<<=15,x+=rand();
    x<<=15,x+=rand();
    return x%mod+1;
}
int query(int x,int y){
    putchar('?'),putchar(' ');
    write(x),putchar(' ');
    write(y),putchar('\n');
    fflush(stdout);
    return read();
}
void print(int x,int y){
    putchar('!'),putchar(' ');
    write(x),putchar(' ');
    write(y),putchar('\n');
    fflush(stdout);
    int res=read();
    if(res==-1)exit(0);
}
int n,ans;
bool check(int x,int y){
    if(y<x)swap(x,y);
    int dis=min(y-x,x+n-y);
    ans=query(x,y);
    return ans!=dis;
}
void solve(){
    n=read();
    int x=getrand(n),y=x+1+getrand(n-3);if(y>n)y-=n;
    while(!check(x,y)){
        x=getrand(n),y=x+1+getrand(n-3);
        if(y>n)y-=n;
    }
    if(x>y)swap(x,y);
    bool dirx=0,diry=0;
    if(query(x%n+1,y)==ans-1)dirx=1;
    if(query(x,y%n+1)==ans-1)diry=1;
    if(dirx){
        int l=x+1,r=y-1,res=x;
        while(l<=r){
            int mid=(l+r)/2;
            if(query(mid,y)==ans-(mid-x))res=mid,l=mid+1;
            else r=mid-1;
        }
        ans-=res-x+1,x=res;
    }else{
        int l=y+1,r=n+x-1,res=n+x;
        while(l<=r){
            int mid=(l+r)/2;int v=mid;if(v>n)v-=n;
            if(query(v,y)==ans-(n+x-mid))res=mid,r=mid-1;
            else l=mid+1;
        }
        ans-=(n+x)-res+1,x=res;
    }
    if(diry)y+=ans;
    else y+=n-ans;
    if(x>n)x-=n;
    if(y>n)y-=n;
    print(x,y);
}
int main(){
    srand(time(0));
    // freopen("identify.in","r",stdin);
    // freopen("identify.out","w",stdout);
    int T=read();
    while(T--)solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3584kb

input:

2
6
2
2
1
1
2
2
2
1
4
2
2
1
1
1
1
1

output:

? 1 5
? 1 3
? 2 4
? 3 4
? 2 5
? 6 4
? 1 4
! 2 4
? 2 4
? 2 4
? 1 3
? 2 3
? 1 4
? 4 3
! 1 3

result:

ok ok (2 test cases)

Test #2:

score: 0
Accepted
time: 5ms
memory: 3584kb

input:

1000
15
4
6
5
6
4
6
5
1
19
5
1
2
2
5
4
3
2
1
17
4
7
4
7
5
4
4
4
3
4
1
15
7
7
5
2
4
7
7
7
6
7
5
2
1
2
1
14
4
5
3
3
4
3
1
15
2
1
3
4
2
1
1
17
2
4
5
3
4
2
5
6
5
4
1
20
5
6
4
4
6
5
4
1
13
3
3
2
4
2
3
3
4
4
3
4
4
1
18
4
4
2
3
2
2
4
2
3
1
13
6
5
4
4
2
2
1
14
3
3
4
4
2
1
1
17
7
8
7
4
6
6
1
12
3
4
4
3
3
2
1...

output:

? 10 14
? 4 12
? 5 12
? 4 13
? 8 12
? 6 12
? 5 12
! 5 8
? 1 15
? 3 12
? 4 12
? 3 13
? 17 12
? 19 12
? 1 12
? 2 12
! 3 12
? 1 5
? 7 14
? 4 8
? 8 15
? 1 9
? 2 9
? 1 10
? 5 9
? 3 9
? 4 9
! 3 11
? 8 15
? 1 9
? 5 10
? 11 13
? 10 14
? 5 12
? 7 14
? 8 15
? 7 15
? 8 15
? 7 1
? 3 15
? 1 15
? 2 15
! 3 1
? 6 1...

result:

ok ok (1000 test cases)

Test #3:

score: 0
Accepted
time: 12ms
memory: 3584kb

input:

1000
21
10
7
7
8
6
3
5
4
1
22
6
5
5
6
6
5
1
20
6
5
7
6
4
5
1
22
10
9
9
5
3
4
4
1
21
3
8
3
3
2
2
3
2
3
1
21
2
7
9
10
9
4
2
2
1
24
2
7
3
2
4
4
1
2
1
22
6
9
8
10
5
7
6
6
1
21
4
5
3
6
4
2
3
1
23
9
4
9
9
8
6
9
7
8
1
21
2
8
8
5
4
3
3
4
2
3
1
24
3
7
6
8
1
3
2
1
20
2
2
4
8
7
9
4
2
1
1
1
24
8
8
5
6
6
7
8
11
...

output:

? 5 16
? 4 12
? 5 12
? 4 13
? 18 12
? 21 12
? 19 12
? 20 12
! 21 10
? 2 13
? 3 13
? 2 14
? 7 13
? 4 13
? 3 13
! 3 17
? 3 14
? 4 14
? 3 15
? 8 14
? 5 14
? 6 14
! 5 11
? 1 12
? 2 12
? 1 13
? 6 12
? 9 12
? 7 12
? 8 12
! 7 15
? 17 20
? 2 15
? 7 10
? 6 12
? 7 12
? 6 13
? 9 12
? 7 12
? 8 12
! 7 13
? 9 11
...

result:

ok ok (1000 test cases)

Test #4:

score: 0
Accepted
time: 7ms
memory: 3584kb

input:

1000
25
2
3
3
10
6
3
2
1
1
25
10
2
4
8
2
9
8
8
2
9
8
8
7
6
8
7
1
25
3
3
7
5
10
6
7
7
4
3
4
1
25
11
10
10
7
8
9
1
26
5
6
5
7
4
5
4
1
26
4
4
3
3
10
5
2
3
1
26
8
11
12
10
6
9
9
10
1
27
13
9
10
5
9
8
10
4
3
4
1
25
3
3
2
2
3
2
1
27
5
2
7
4
6
5
7
5
6
6
5
6
6
9
10
8
7
6
1
27
6
11
10
4
10
10
3
3
6
5
7
4
4
1...

output:

? 2 6
? 3 6
? 2 7
? 16 6
? 21 6
? 24 6
? 25 6
? 1 6
! 1 6
? 2 17
? 10 12
? 12 16
? 2 19
? 10 12
? 2 18
? 5 22
? 17 25
? 19 21
? 6 20
? 7 20
? 6 21
? 13 20
? 9 20
? 11 20
? 10 20
! 9 25
? 1 4
? 16 19
? 12 19
? 13 18
? 3 13
? 9 25
? 10 25
? 9 1
? 4 25
? 6 25
? 5 25
! 6 23
? 8 21
? 9 21
? 8 22
? 14 21
...

result:

ok ok (1000 test cases)

Test #5:

score: -100
Time Limit Exceeded

input:

1000
29
5
6
4
7
7
5
4
1
28
10
9
9
7
7
8
1
30
10
9
9
7
7
7
6
1
29
6
5
5
9
4
4
3
1
28
4
5
5
10
5
3
2
1
29
5
2
3
1
7
6
4
3
1
29
8
9
10
8
3
5
3
2
1
28
3
3
4
12
7
4
3
2
1
30
5
6
6
6
3
3
2
1
30
9
10
10
3
5
3
2
1
28
10
11
10
10
4
3
3
2
1
29
2
6
5
7
4
5
4
1
29
11
12
10
4
3
5
5
1
29
8
7
9
8
4
6
5
1
29
13
14
...

output:

? 4 19
? 5 19
? 4 20
? 26 19
? 29 19
? 2 19
? 3 19
! 3 22
? 5 18
? 6 18
? 5 19
? 11 18
? 8 18
? 9 18
! 8 24
? 13 27
? 14 27
? 13 28
? 20 27
? 16 27
? 18 27
? 17 27
! 17 2
? 10 29
? 11 29
? 10 1
? 19 29
? 14 29
? 12 29
? 13 29
! 13 2
? 16 24
? 17 24
? 16 25
? 6 24
? 11 24
? 13 24
? 14 24
! 14 23
? 19...

result: