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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#define pb push_back
#define mp make_pair
#define taskname "A"
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const int maxn = 1e5 + 5;
int p[maxn][3];
int get(int x){
return min({p[x][0] , p[x][1] , p[x][2]});
}
ii s[maxn * 4];
int lz[maxn * 4];
int n , q;
void build(int x , int l , int r){
if(l == r){
s[x] = mp(-l , l);
return;
}
int mid = l + r >> 1;
build(x * 2 , l , mid);
build(x * 2 + 1 , mid + 1 , r);
s[x] = min(s[x * 2] , s[x * 2 + 1]);
}
void push(int x , bool key){
s[x].first += lz[x];
if(key){
lz[x * 2] += lz[x];
lz[x * 2 + 1] += lz[x];
}
lz[x] = 0;
}
void update(int x , int l , int r , int L , int val){
push(x,l!=r);
if(L > r)return;
if(L <= l){
lz[x] += val;
push(x , l != r);
return;
}
int mid = l + r >> 1;
update(x * 2 , l , mid , L , val);
update(x * 2 + 1 , mid + 1 , r , L , val);
s[x] = min(s[x * 2] , s[x * 2 + 1]);
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
if(fopen(taskname".INP","r")){
freopen(taskname".INP", "r",stdin);
freopen(taskname".OUT", "w",stdout);
}
cin >> n >> q;
build(1,1,n);
for(int i = 0 ; i < 3 ; ++i){
for(int j = 1 ; j <= n ; ++j){
int x;cin >> x;
p[x][i] = j;
}
}
build(1,1,n);
for(int i = 1 ; i <= n ; ++i){
update(1,1,n,get(i),1);
}
while(q--){
int key;cin >> key;
if(key == 1){
int x;cin >> x;
cout << (get(x) <= s[1].second ? "DA\n" : "NE\n");
}else{
int i , a , b;cin >> i >> a >> b;--i;
update(1,1,n,get(a),-1);
update(1,1,n,get(b),-1);
swap(p[a][i],p[b][i]);
update(1,1,n,get(a),1);
update(1,1,n,get(b),1);
}
}
}
Compilation message (stderr)
tenis.cpp: In function 'void build(int, int, int)':
tenis.cpp:30:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l + r >> 1;
~~^~~
tenis.cpp: In function 'void update(int, int, int, int, int)':
tenis.cpp:51:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l + r >> 1;
~~^~~
tenis.cpp: In function 'int main()':
tenis.cpp:62:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen(taskname".INP", "r",stdin);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
tenis.cpp:63:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen(taskname".OUT", "w",stdout);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |