# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
167680 |
2019-12-09T12:28:14 Z |
Atill83 |
Tenis (COI19_tenis) |
C++14 |
|
105 ms |
8056 KB |
#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 1e5+5;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n, q;
int a[MAXN], b[MAXN], c[MAXN];
ll yer1[MAXN], yer2[MAXN], yer3[MAXN], mx[MAXN];
pair<int,bool> t[4*MAXN];
int hali[4*MAXN];
void build(int v, int tl, int tr){
if(tl == tr){
t[v].ff = max(mx[a[tl]], max(mx[b[tl]], mx[c[tl]]));
if(t[v].ff <= tl){
t[v].ss = 1;
}else{
t[v].ss = 0;
}
hali[v] = t[v].ff;
}else{
int tm = (tl + tr) / 2;
build(2*v, tl, tm);
build(2*v + 1, tm + 1, tr);
hali[v] = max(hali[2*v], hali[2*v + 1]);
if(t[2*v].ss){
if(t[2*v + 1].ss){
t[v].ff = t[2*v + 1].ff;
}else{
t[v].ff = t[2*v].ff;
}
t[v].ss = 1;
}else if(t[2*v + 1].ss){
if(t[2*v].ff <= t[2*v + 1].ff){
t[v].ff = t[2*v + 1].ff;
t[v].ss = 1;
}else{
t[v].ff = hali[v];
t[v].ss = 0;
}
}else{
t[v].ff = hali[v];
t[v].ss = 0;
}
}
}
void upd(int v, int tl , int tr, int pos){
if(tl == tr){
t[v].ff = max(mx[a[tl]], max(mx[b[tl]], mx[c[tl]]));
if(t[v].ff <= tl){
t[v].ss = 1;
}else{
t[v].ss = 0;
}
hali[v] = t[v].ff;
}else{
int tm = (tl + tr) / 2;
if(pos <= tm)
upd(2*v, tl, tm, pos);
else
upd(2*v + 1, tm + 1, tr, pos);
hali[v] = max(hali[2*v], hali[2*v + 1]);
if(t[2*v].ss){
if(t[2*v + 1].ss){
t[v].ff = t[2*v + 1].ff;
}else{
t[v].ff = t[2*v].ff;
}
t[v].ss = 1;
}else if(t[2*v + 1].ss){
if(t[2*v].ff <= t[2*v + 1].ff){
t[v].ff = t[2*v + 1].ff;
t[v].ss = 1;
}else{
t[v].ff = hali[v];
t[v].ss = 0;
}
}else{
t[v].ff = hali[v];
t[v].ss = 0;
}
}
}
pair<int, bool> que(int v, int tl, int tr, int l, int r){
if(l > r) return {-1, 0};
else if(tl == l && r == tr){
return t[v];
}else{
int tm = (tl + tr)/2;
pair<int, bool> ans1 = que(2*v, tl, tm, l, min(tm, r)),
ans2 = que(2*v + 1, tm + 1, tr, max(tm + 1, l), r);
if(ans1.ss){
return ans1;
}else if(ans2.ss){
if(ans1.ff <= ans2.ff){
return {ans2.ff, 1};
}else{
return {ans1.ff, 0};
}
}else{
return {max(ans1.ff, ans2.ff), 0};
}
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
#ifdef Local
freopen("../IO/int.txt","r",stdin);
freopen("../IO/out.txt","w",stdout);
#endif
cin>>n>>q;
for(int i = 1; i <= n; i++){
cin>>a[i];
yer1[a[i]] = i;
}
for(int i = 1; i <= n; i++){
cin>>b[i];
yer2[b[i]] = i;
}
for(int i = 1; i <= n; i++){
cin>>c[i];
yer3[c[i]] = i;
mx[c[i]] = max(yer3[c[i]], max(yer2[c[i]], yer1[c[i]]));
}
build(1, 1, n);
while(q--){
int type;
cin>>type;
//cout<<type<<endl;
if(type == 1){
int x;
cin>>x;
//cout<<que(1, 1, n,1,min(yer1[x], min(yer2[x], yer3[x])) - 1).ff<<endl;
if(que(1, 1, n, 1, min(yer1[x], min(yer2[x], yer3[x])) - 1).ss){
cout<<"NE"<<endl;
}else{
cout<<"DA"<<endl;
}
}else{
int court, l, r;
cin>>court>>l>>r;
if(court == 1){
swap(a[yer1[l]], a[yer1[r]]);
swap(yer1[l], yer1[r]);
ll cur1 = l, cur2 = r;
mx[cur1] = max(yer3[cur1], max(yer2[cur1], yer1[cur1]));
mx[cur2] = max(yer3[cur2], max(yer2[cur2], yer1[cur2]));
}else if(court == 2){
swap(b[yer2[l]], b[yer2[r]]);
swap(yer2[l], yer2[r]);
ll cur1 = l, cur2 = r;
mx[cur1] = max(yer3[cur1], max(yer2[cur1], yer1[cur1]));
mx[cur2] = max(yer3[cur2], max(yer2[cur2], yer1[cur2]));
}else{
swap(c[yer3[l]], c[yer3[r]]);
swap(yer3[l], yer3[r]);
ll cur1 = l, cur2 = r;
mx[cur1] = max(yer3[cur1], max(yer2[cur1], yer1[cur1]));
mx[cur2] = max(yer3[cur2], max(yer2[cur2], yer1[cur2]));
}
upd(1, 1, n, yer1[l]);
upd(1, 1, n, yer1[r]);
upd(1, 1, n, yer2[l]);
upd(1, 1, n, yer2[r]);
upd(1, 1, n, yer3[l]);
upd(1, 1, n, yer3[r]);
}
}
#ifdef Local
cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
#endif
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Incorrect |
2 ms |
380 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Incorrect |
2 ms |
380 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
105 ms |
8056 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Incorrect |
2 ms |
380 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |