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>
#define REP(i,a,b) for (auto i = (a); i <= (b); ++i)
#define PER(i,a,b) for (auto i = (b); i >= (a); --i)
#define log2(x) (31-__builtin_clz(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define SZ(x) (int)(x).size()
#define mup(x,y) x = min(x,y)
#define Mup(x,y) x = max(x,y)
#define debug(x) cout << #x << " is " << x << el
#define el '\n'
using namespace std; using ll = long long; using ii = pair<int,int>; using iii = tuple<int,int,int>;
void solution(); int main() {ios::sync_with_stdio(0); cin.tie(0); solution();}
const int N = 400'003;
int n, q, plate[N];
void input() {
cin >> n >> q;
REP(i,1,n) cin >> plate[i];
}
void solution() {
input();
REP(i,1,q) {
int s, t, p; cin >> s >> t >> p;
if (s <= t) {
REP(i,s,t) if (p < plate[i]) swap(p,plate[i]);
} else {
REP(i,s,n) if (p < plate[i]) swap(p,plate[i]);
REP(i,1,t) if (p < plate[i]) swap(p,plate[i]);
}
cout << p << el;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |