Submission #117625

#TimeUsernameProblemLanguageResultExecution timeMemory
117625BruteforcemanTenis (COI19_tenis)C++11
51 / 100
1070 ms4884 KiB
    #include "bits/stdc++.h"
    using namespace std;
    int N, Q;
    int a[4][100010];
    int p[4][100010];
     
    int opt() {
    	int mx1 = 0;
    	int mx2 = 0;
    	for(int i = 1; i <= N; i++) {
    		mx1 = max(mx1, a[2][i]);
    		mx2 = max(mx2, a[3][i]);
    		if(mx1 == mx2 && mx1 == i) {
    			return i;
    		}
    	}
    	return N + 1;
    }
     
    void update(int q, int x, int y) {
    	if(q == 1) {
    		update(2, x, y);
    		update(3, x, y);
    		swap(p[1][a[1][x]], p[1][a[1][y]]);
    		swap(a[1][x], a[1][y]);
    	} else {
    		int f = p[q][x];
    		int g = p[q][y];
    		swap(a[q][f], a[q][g]);
    		swap(p[q][x], p[q][y]);
    	}
    	// cout << endl;
    	// for(int i = 2; i <= 3; i++) {
    	// 	for(int j = 1; j <= N; j++) {
    	// 		cout << a[i][j] << ' ';
    	// 	}
    	// 	cout << endl;
    	// }
    }
     
    int main(int argc, char const *argv[])
    {
    	scanf("%d %d", &N, &Q);
    	for(int i = 1; i <= 3; i++) {
    		for(int j = 1; j <= N; j++) {
    			scanf("%d", &a[i][j]);
    			p[i][a[i][j]] = j;
    		}
    	}
    	for(int i = 2; i <= 3; i++) {
    		for(int j = 1; j <= N; j++) {
    			a[i][j] = p[1][a[i][j]];
    			p[i][a[i][j]] = j;
    			// cout << a[i][j] << ' ';
    		}
    		// cout << endl;
    	}
     
    	int first = opt();
    	for(int i = 1; i <= Q; i++) {
    		int c;
    		scanf("%d", &c);
    		if(c == 1) {
    			int x;
    			scanf("%d", &x);
    			if(p[1][x] <= first) printf("DA\n");
    			else printf("NE\n");
    		} else {
    			int f, x, y;
    			scanf("%d %d %d", &f, &x, &y);
    			update(f, p[1][x], p[1][y]);
    			first = opt();
    		}
    	}	
    	return 0;
    }

Compilation message (stderr)

tenis.cpp: In function 'int main(int, const char**)':
tenis.cpp:43:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
      scanf("%d %d", &N, &Q);
      ~~~~~^~~~~~~~~~~~~~~~~
tenis.cpp:46:13: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
        scanf("%d", &a[i][j]);
        ~~~~~^~~~~~~~~~~~~~~~
tenis.cpp:62:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%d", &c);
       ~~~~~^~~~~~~~~~
tenis.cpp:65:13: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
        scanf("%d", &x);
        ~~~~~^~~~~~~~~~
tenis.cpp:70:13: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
        scanf("%d %d %d", &f, &x, &y);
        ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...