Codeforces Round 838 (Div. 2) D. GCD Queries

题目

思路:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define se second
#define lson p << 1
#define rson p << 1 | 1
const int maxn = 1e6 + 5, inf = 1e9, maxm = 4e4 + 5;
const int N = 1e6;
// const int mod = 1e9 + 7;
const int mod = 998244353;
// int a[505][5005];
// bool vis[505][505];
// char s[505][505];
int a[maxn], b[maxn];
int vis[maxn];
string s;
int n, m;

struct Node{
    int val, id;
    bool operator<(const Node &u)const{
        return val < u.val;
    }
};
// Node c[maxn];

int ans[maxn];
int pre[maxn];

//long long ? maxn ?

void solve(){
    int res = 0;
    int q, k;
    int sum = 0;
    int mx = 0;
    cin >> n;
    // for(int i = 1; i <= n; i++){
    //     cin >> a[i];
    // }
    int l = 1, r = 2;
    int x, y;
    for(int i = 3; i <= n; i++){
        cout << "? " << l << ' ' << i << '\n';
        cout.flush();
        cin >> x;
        cout << "? " << r << ' ' << i << '\n';
        cout.flush();
        cin >> y;
        if(x < y){
            l = r;
            r = i;
        }
        else if(x > y){
            r = i;
        }
    }
    cout << "! " << l << ' ' << r << '\n';
    cout.flush();
    cin >> res;
}
    
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int T = 1;
    cin >> T;
    while (T--)
    {
        solve();
    }
    return 0;
}

相关推荐

  1. Codeforces Round 835 (Div. 4)

    2024-03-30 16:30:03       43 阅读
  2. Codeforces Round 898 (Div. 4)

    2024-03-30 16:30:03       50 阅读
  3. Codeforces Round 912 (Div. 2)

    2024-03-30 16:30:03       60 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-30 16:30:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-30 16:30:03       100 阅读
  3. 在Django里面运行非项目文件

    2024-03-30 16:30:03       82 阅读
  4. Python语言-面向对象

    2024-03-30 16:30:03       91 阅读

热门阅读

  1. 用静态工厂方法代替构造器

    2024-03-30 16:30:03       35 阅读
  2. AI每周更新:追踪人工智能研究进展

    2024-03-30 16:30:03       44 阅读
  3. 代码随想录算法训练营总结

    2024-03-30 16:30:03       41 阅读
  4. 【LeetCode】合并两个有序数组

    2024-03-30 16:30:03       49 阅读
  5. Python搜索算法——二分搜索

    2024-03-30 16:30:03       41 阅读
  6. 代码随想录算法训练营第三十二天|leetcode738题

    2024-03-30 16:30:03       46 阅读
  7. npm 常用命令详解

    2024-03-30 16:30:03       35 阅读
  8. Qt_Note18_QML_c++与qml信号与槽

    2024-03-30 16:30:03       43 阅读