Submission #14080549


Source Code Expand

Copy
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














int N, Q, A[201010];
//---------------------------------------------------------------------------------------------------
set<int> badpairs;
// swap the x-th item and the (x+1)-th item
void myswap(int x) {
	rep(d, -1, 2) if (badpairs.count(x - d)) badpairs.erase(x - d);
	swap(A[x], A[x + 1]);
	rep(d, -1, 2) if (0 <= x + d && x + d + 1 < N && A[x + d] > A[x + d + 1]) badpairs.insert(x + d);
}
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> Q;
	rep(i, 0, N) A[i] = i + 1;
	badpairs.insert(inf);

	rep(_, 0, Q) {
		int t, x, y; cin >> t >> x >> y;
		x--; y--;

		if (t == 1) {
			myswap(x);
		}
		else {
			while (true) {
				auto ite = badpairs.lower_bound(x);
				if (y <= *ite) break;
				myswap(*ite);
			}
		}
	}

	rep(i, 0, N) {
		if(i) printf(" ");
		printf("%d", A[i]);
	}
	printf("\n");
}





Submission Info

Submission Time
Task N - Swap and Sort
User hamayanhamayan
Language C++ (GCC 9.2.1)
Score 6
Code Size 2206 Byte
Status AC
Exec Time 189 ms
Memory 7328 KB

Judge Result

Set Name All Sample
Score / Max Score 6 / 6 0 / 0
Status
AC × 22
AC × 2
Set Name Test Cases
All sample_01.txt, sample_02.txt, testcase_1.txt, testcase_10.txt, testcase_11.txt, testcase_12.txt, testcase_13.txt, testcase_14.txt, testcase_15.txt, testcase_16.txt, testcase_17.txt, testcase_18.txt, testcase_19.txt, testcase_2.txt, testcase_20.txt, testcase_3.txt, testcase_4.txt, testcase_5.txt, testcase_6.txt, testcase_7.txt, testcase_8.txt, testcase_9.txt
Sample sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
sample_01.txt AC 2 ms 3596 KB
sample_02.txt AC 2 ms 3700 KB
testcase_1.txt AC 87 ms 4540 KB
testcase_10.txt AC 78 ms 3676 KB
testcase_11.txt AC 118 ms 3588 KB
testcase_12.txt AC 57 ms 4484 KB
testcase_13.txt AC 62 ms 4536 KB
testcase_14.txt AC 71 ms 4340 KB
testcase_15.txt AC 82 ms 4388 KB
testcase_16.txt AC 102 ms 4460 KB
testcase_17.txt AC 185 ms 7256 KB
testcase_18.txt AC 75 ms 3672 KB
testcase_19.txt AC 102 ms 3608 KB
testcase_2.txt AC 53 ms 4556 KB
testcase_20.txt AC 123 ms 4600 KB
testcase_3.txt AC 78 ms 4488 KB
testcase_4.txt AC 189 ms 7328 KB
testcase_5.txt AC 186 ms 7324 KB
testcase_6.txt AC 35 ms 3760 KB
testcase_7.txt AC 45 ms 3712 KB
testcase_8.txt AC 50 ms 3596 KB
testcase_9.txt AC 60 ms 3608 KB