#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define owo(i,a, b) for(auto i=(a);i<(b); ++i)
#define uwu(i,a, b) for(auto i=(a)-1; i>=(b); --i)
#define senpai push_back
#define ttgl pair<int, int>
#define ayaya cout<<"ayaya~"<<endl
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ttgl, null_type,less<ttgl>, rb_tree_tag,tree_order_statistics_node_update>*/
using ll = long long;
using ld = long double;
const ll MOD = 998244353;
const ll root = 62;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll binpow(ll a,ll b){ll res=1;while(b){if(b&1)res=(res*a)%MOD;a=(a*a)%MOD;b>>=1;}return res;}
ll modInv(ll a){return binpow(a, MOD-2);}
const double PI = acos(-1);
const double eps = 1e-10;
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll NINFLL = 0xc0c0c0c0c0c0c0c0;
const int mxN = 100001;
int n, q;
int arr[mxN][3];
int pos[mxN][3];
int val[mxN];
int sgmin[4*mxN];
int del[4*mxN];
void push(int i) {
del[2*i]+=del[i];
del[2*i+1]+=del[i];
del[i] = 0;
}
void pull(int i) {
sgmin[i] = min(sgmin[2*i] + del[2*i], sgmin[2*i+1] + del[2*i+1]);
}
void upd(int l, int r, int ch, int i = 1, int le = 0, int rr = n-1) {
//cout<<l<<" "<<r<<" "<<ch<<" "<<i<<" "<<le<<" "<<rr<<endl;
if(le > r || rr < l) return;
if(le >= l && rr <= r) {
del[i]+=ch;
return;
}
push(i);
int m = (le + rr) >> 1;
upd(l, r, ch, 2*i, le, m);
upd(l, r, ch, 2*i+1, m+1, rr);
pull(i);
}
int query(int i = 1, int l = 0, int r = n-1) {
if(l==r)return l;
push(i);
pull(i);
int m = (l + r) >> 1;
//cout<<i<<" "<<l<<" "<<r<<" "<<(sgmin[2*i] + del[2*i])<<"\n";
if(sgmin[2*i] + del[2*i]==0) {
return query(2*i, l, m);
}
return query(2*i+1, m+1, r);
}
int main() {
//freopen("file.in", "r", stdin);
//freopen("file.out", "w", stdout);
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
cin.tie(0)->sync_with_stdio(0);
cin>>n>>q;
owo(i, 0, 3)owo(j, 0, n) {
cin>>arr[j][i];
arr[j][i]--;
val[arr[j][i]] = max(val[arr[j][i]], j);
pos[arr[j][i]][i] = j;
}
owo(i, 0, n) {
upd(i, i, i+1);
upd(val[i], n-1, -1);
//cout<<i<<" "<<val[i]<<"\n";
}
int a, b, c, d;
while(q--) {
cin>>a;
if(a==1) {
cin>>b;
b--;
//cout<<query()<<"\n";
cout<<(val[b]<=query() ? "DA\n" : "NE\n");
}else {
cin>>b>>c>>d;
b--; c--; d--;
upd(val[c], n-1, 1);
upd(val[d], n-1, 1);
//cout<<pos[c][b]<<" "<<pos[d][b]<<" "<<arr[pos[c][b]][b]<<" "<<arr[pos[d][b]][b]<<"-_- \n";
swap(pos[c][b], pos[d][b]);
swap(arr[pos[c][b]][b], arr[pos[d][b]][b]);
val[c] = 0; val[d] = 0;
owo(k, 0, 3) {
val[c] = max(val[c], pos[c][k]);
val[d] = max(val[d], pos[d][k]);
}
// cout<<val[c]<<" "<<val[d]<<"hi \n";
upd(val[c], n-1, -1);
upd(val[d], n-1, -1);
}
}
return 0;
}
Compilation message
tenis.cpp:2: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
2 | #pragma GCC optimization ("O3")
|
tenis.cpp:3: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
3 | #pragma GCC optimization ("unroll-loops")
|
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
404 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
404 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
404 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
95 ms |
6392 KB |
Output is correct |
14 |
Correct |
97 ms |
6408 KB |
Output is correct |
15 |
Correct |
101 ms |
6520 KB |
Output is correct |
16 |
Correct |
95 ms |
6264 KB |
Output is correct |
17 |
Correct |
106 ms |
6392 KB |
Output is correct |
18 |
Correct |
112 ms |
6520 KB |
Output is correct |
19 |
Correct |
99 ms |
6264 KB |
Output is correct |
20 |
Correct |
105 ms |
6392 KB |
Output is correct |
21 |
Correct |
103 ms |
6392 KB |
Output is correct |
22 |
Correct |
105 ms |
6520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
161 ms |
7544 KB |
Output is correct |
2 |
Correct |
153 ms |
7544 KB |
Output is correct |
3 |
Correct |
131 ms |
7416 KB |
Output is correct |
4 |
Correct |
137 ms |
7416 KB |
Output is correct |
5 |
Correct |
131 ms |
7492 KB |
Output is correct |
6 |
Correct |
135 ms |
7484 KB |
Output is correct |
7 |
Correct |
128 ms |
7480 KB |
Output is correct |
8 |
Correct |
137 ms |
7416 KB |
Output is correct |
9 |
Correct |
137 ms |
7416 KB |
Output is correct |
10 |
Correct |
133 ms |
7416 KB |
Output is correct |
11 |
Correct |
128 ms |
7544 KB |
Output is correct |
12 |
Correct |
133 ms |
7544 KB |
Output is correct |
13 |
Correct |
154 ms |
7416 KB |
Output is correct |
14 |
Correct |
129 ms |
7416 KB |
Output is correct |
15 |
Correct |
135 ms |
7416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
404 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
95 ms |
6392 KB |
Output is correct |
14 |
Correct |
97 ms |
6408 KB |
Output is correct |
15 |
Correct |
101 ms |
6520 KB |
Output is correct |
16 |
Correct |
95 ms |
6264 KB |
Output is correct |
17 |
Correct |
106 ms |
6392 KB |
Output is correct |
18 |
Correct |
112 ms |
6520 KB |
Output is correct |
19 |
Correct |
99 ms |
6264 KB |
Output is correct |
20 |
Correct |
105 ms |
6392 KB |
Output is correct |
21 |
Correct |
103 ms |
6392 KB |
Output is correct |
22 |
Correct |
105 ms |
6520 KB |
Output is correct |
23 |
Correct |
161 ms |
7544 KB |
Output is correct |
24 |
Correct |
153 ms |
7544 KB |
Output is correct |
25 |
Correct |
131 ms |
7416 KB |
Output is correct |
26 |
Correct |
137 ms |
7416 KB |
Output is correct |
27 |
Correct |
131 ms |
7492 KB |
Output is correct |
28 |
Correct |
135 ms |
7484 KB |
Output is correct |
29 |
Correct |
128 ms |
7480 KB |
Output is correct |
30 |
Correct |
137 ms |
7416 KB |
Output is correct |
31 |
Correct |
137 ms |
7416 KB |
Output is correct |
32 |
Correct |
133 ms |
7416 KB |
Output is correct |
33 |
Correct |
128 ms |
7544 KB |
Output is correct |
34 |
Correct |
133 ms |
7544 KB |
Output is correct |
35 |
Correct |
154 ms |
7416 KB |
Output is correct |
36 |
Correct |
129 ms |
7416 KB |
Output is correct |
37 |
Correct |
135 ms |
7416 KB |
Output is correct |
38 |
Correct |
236 ms |
7720 KB |
Output is correct |
39 |
Correct |
164 ms |
7472 KB |
Output is correct |
40 |
Correct |
239 ms |
7928 KB |
Output is correct |
41 |
Correct |
176 ms |
7824 KB |
Output is correct |
42 |
Correct |
195 ms |
7616 KB |
Output is correct |
43 |
Correct |
242 ms |
7780 KB |
Output is correct |
44 |
Correct |
164 ms |
7484 KB |
Output is correct |
45 |
Correct |
176 ms |
7544 KB |
Output is correct |
46 |
Correct |
150 ms |
7480 KB |
Output is correct |
47 |
Correct |
165 ms |
7544 KB |
Output is correct |
48 |
Correct |
148 ms |
7468 KB |
Output is correct |
49 |
Correct |
189 ms |
7612 KB |
Output is correct |
50 |
Correct |
165 ms |
7552 KB |
Output is correct |
51 |
Correct |
171 ms |
7668 KB |
Output is correct |
52 |
Correct |
242 ms |
7744 KB |
Output is correct |
53 |
Correct |
173 ms |
7740 KB |
Output is correct |
54 |
Correct |
188 ms |
7544 KB |
Output is correct |
55 |
Correct |
185 ms |
7544 KB |
Output is correct |
56 |
Correct |
175 ms |
7620 KB |
Output is correct |
57 |
Correct |
156 ms |
7544 KB |
Output is correct |
58 |
Correct |
190 ms |
7544 KB |
Output is correct |