Submission #241459

# Submission time Handle Problem Language Result Execution time Memory
241459 2020-06-24T08:16:17 Z Mercenary Tenis (COI19_tenis) C++14
100 / 100
240 ms 7800 KB
#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

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
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 69 ms 6272 KB Output is correct
14 Correct 68 ms 6264 KB Output is correct
15 Correct 85 ms 6264 KB Output is correct
16 Correct 70 ms 6264 KB Output is correct
17 Correct 83 ms 6392 KB Output is correct
18 Correct 69 ms 6264 KB Output is correct
19 Correct 69 ms 6264 KB Output is correct
20 Correct 68 ms 6264 KB Output is correct
21 Correct 68 ms 6392 KB Output is correct
22 Correct 74 ms 6392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 103 ms 7428 KB Output is correct
2 Correct 92 ms 7416 KB Output is correct
3 Correct 97 ms 7452 KB Output is correct
4 Correct 97 ms 7544 KB Output is correct
5 Correct 92 ms 7416 KB Output is correct
6 Correct 97 ms 7416 KB Output is correct
7 Correct 98 ms 7416 KB Output is correct
8 Correct 108 ms 7416 KB Output is correct
9 Correct 88 ms 7416 KB Output is correct
10 Correct 93 ms 7416 KB Output is correct
11 Correct 89 ms 7392 KB Output is correct
12 Correct 100 ms 7416 KB Output is correct
13 Correct 95 ms 7416 KB Output is correct
14 Correct 98 ms 7392 KB Output is correct
15 Correct 92 ms 7416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 69 ms 6272 KB Output is correct
14 Correct 68 ms 6264 KB Output is correct
15 Correct 85 ms 6264 KB Output is correct
16 Correct 70 ms 6264 KB Output is correct
17 Correct 83 ms 6392 KB Output is correct
18 Correct 69 ms 6264 KB Output is correct
19 Correct 69 ms 6264 KB Output is correct
20 Correct 68 ms 6264 KB Output is correct
21 Correct 68 ms 6392 KB Output is correct
22 Correct 74 ms 6392 KB Output is correct
23 Correct 103 ms 7428 KB Output is correct
24 Correct 92 ms 7416 KB Output is correct
25 Correct 97 ms 7452 KB Output is correct
26 Correct 97 ms 7544 KB Output is correct
27 Correct 92 ms 7416 KB Output is correct
28 Correct 97 ms 7416 KB Output is correct
29 Correct 98 ms 7416 KB Output is correct
30 Correct 108 ms 7416 KB Output is correct
31 Correct 88 ms 7416 KB Output is correct
32 Correct 93 ms 7416 KB Output is correct
33 Correct 89 ms 7392 KB Output is correct
34 Correct 100 ms 7416 KB Output is correct
35 Correct 95 ms 7416 KB Output is correct
36 Correct 98 ms 7392 KB Output is correct
37 Correct 92 ms 7416 KB Output is correct
38 Correct 240 ms 7672 KB Output is correct
39 Correct 155 ms 7416 KB Output is correct
40 Correct 192 ms 7672 KB Output is correct
41 Correct 150 ms 7564 KB Output is correct
42 Correct 143 ms 7544 KB Output is correct
43 Correct 197 ms 7672 KB Output is correct
44 Correct 149 ms 7544 KB Output is correct
45 Correct 141 ms 7572 KB Output is correct
46 Correct 121 ms 7544 KB Output is correct
47 Correct 126 ms 7544 KB Output is correct
48 Correct 116 ms 7416 KB Output is correct
49 Correct 148 ms 7544 KB Output is correct
50 Correct 146 ms 7544 KB Output is correct
51 Correct 130 ms 7544 KB Output is correct
52 Correct 187 ms 7800 KB Output is correct
53 Correct 130 ms 7544 KB Output is correct
54 Correct 149 ms 7544 KB Output is correct
55 Correct 133 ms 7544 KB Output is correct
56 Correct 149 ms 7544 KB Output is correct
57 Correct 116 ms 7544 KB Output is correct
58 Correct 145 ms 7548 KB Output is correct