This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 11;
const int MAXK = 1e5 + 11;
int N, K, Q, T;
int p1[MAXN], p2[MAXN];
int p[MAXK], q[MAXK];
void read_input(){
cin >> N >> K >> Q >> T;
for(int i = 1; i <= N; i++) cin >> p1[i];
for(int i = 1; i <= N; i++) cin >> p2[i];
for(int i = 1; i <= K; i++) cout << i << " \n"[i == K];
cout.flush();
}
struct bump{
int l, r;
};
bump r1[MAXK], r2[MAXK];
bump operator+ (const bump& a, const bump& b){
if(a.r >= b.l){
return {a.l, a.r - b.l + b.r};
}else{
return {a.l - a.r + b.l, b.r};
}
}
void query(int a, int b){
cout << "? " << a << ' ' << b << '\n';
}
void done_query(){
cout << "!" << '\n'; cout.flush();
}
pair<bump, bump> read_query_answer(int a, int b){
int a1, b1, a2, b2; cin >> a1 >> b1 >> a2 >> b2;
return {{a1, b1}, {a2, b2}};
}
int dist(int p, int q, bump a[]){
bump b {0, 0};
for(int i = p; i < q; i++){
b = b + a[i];
}
return b.l + b.r;
}
int32_t main(){
cin.tie(0); cout.tie(0)->sync_with_stdio(false);
read_input();
for(int i = 1; i <= K - 1; i++){
query(i, i + 1);
}
done_query();
for(int i = 1; i <= K - 1; i++){
auto q = read_query_answer(i, i + 1);
r1[i] = q.first, r2[i] = q.second;
}
for(int i = 0; i < T; i++){
cin >> p[i] >> q[i]; if(p[i] > q[i]) swap(p[i], q[i]);
}
for(int i = 0; i < T; i++){
int d1 = dist(p[i], q[i], r1);
int d2 = dist(p[i], q[i], r2);
cout << d1 << ' ' << d2 << '\n';
}
cout.flush();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |