QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#203805#866. Display of SpringsZhou_JKWA 1ms3484kbC++231.7kb2023-10-06 20:38:552023-10-06 20:38:57

Judging History

你现在查看的是最新测评结果

  • [2023-10-06 20:38:57]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3484kb
  • [2023-10-06 20:38:55]
  • 提交

answer

#include<iostream>
#include<cstdio>
using namespace std;
const int M=100005;
int n,m;
string query(int a,int b,int w)
{
    a--,b--;
    cout<<"? "<<a<<" "<<b<<" "<<w<<endl;
    string str;
    cin>>str;
    return str;
}
struct Segment_Tree
{
    #define ls i*2
    #define rs i*2+1
    struct Node
    {
        int tag;
    }tree[M*4];
    void insert(int i,int l,int r,int u)
    {
        if(!tree[i].tag)
        {
            tree[i].tag=u;
            return;
        }
        if(::query(tree[i].tag,u,l)=="SECOND") swap(u,tree[i].tag);
        if(l==r) return;
        int mid=(l+r)/2;
        if(::query(tree[i].tag,u,mid)=="SECOND") insert(ls,l,mid,tree[i].tag),tree[i].tag=u;
        else insert(rs,mid+1,r,u);
        return;
    }
    int query(int i,int l,int r,int u)
    {
        if(l==r) return tree[i].tag;
        int mid=(l+r)/2;
        int p=0;
        if(u<=mid) p=query(ls,l,mid,u);
        else p=query(rs,mid+1,r,u);
        if(!p) return tree[i].tag;
        if(!tree[i].tag) return p;
        if(::query(tree[i].tag,p,u)=="SECOND") return p;
        else return tree[i].tag;
    }
    #undef ls
    #undef rs
}T;
int solve(int w)
{
    return T.query(1,1,m,w);
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr),cout.tie(nullptr);
    cin>>n;
    m=100000;
    for(int i=1;i<=n;i++)
        T.insert(1,1,m,i);
    cout<<"!"<<endl;
    while(true)
    {
        string str;
        cin>>str;
        if(str=="QUESTION")
        {
            int w;
            cin>>w;
            int res=solve(w);
            cout<<"! "<<res<<endl;
        }
        else break;
    }
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3484kb

input:

3
SECOND
FIRST
FIRST
SECOND
QUESTION 2
SECOND

output:

? 0 1 1
? 1 0 50000
? 1 2 1
? 1 2 50000
!
? 2 1 2
! 2

result:

wrong answer Wrong answer