QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#267032#2815. 组合数据结构问题zjj2021AC ✓27ms3504kbC++202.1kb2023-11-26 21:32:112023-11-26 21:32:12

Judging History

你现在查看的是最新测评结果

  • [2023-11-26 21:32:12]
  • 评测
  • 测评结果:AC
  • 用时:27ms
  • 内存:3504kb
  • [2023-11-26 21:32:11]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
typedef long long ll;
typedef double db;
typedef pair<int, int> PII;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;
int lowbit(int x){return x&-x;}
int rnd(int x) {return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
inline ll rd(){ll x=0;char ch;bool f=true;for(ch=getchar();!isdigit(ch);ch=getchar())if(ch=='-')f^=f;for(;isdigit(ch);ch=getchar())x=(x<<3)+(x<<1)+(ch^48);return f?x:-x;}
inline void wr(ll x){if(x<0)putchar('-'),x=-x;if(x>9)wr(x/10);putchar(x%10+48);}
inline void wr(char *s){printf("%s",s);}
// head

const int N = 100010;

void solve() {
	int n;
	cin >> n;
	queue<int> q;
	stack<int> stk;
	priority_queue<int> big;
	priority_queue<int, vector<int>, greater<>> small;
	vector<int> res{1, 1, 1, 1};
	for (int i = 1; i <= n; i ++ ) {
		int o, x;
		cin >> o >> x;
		if (o == 1) {
			q.push(x);
			stk.push(x);
			big.push(x);
			small.push(x);
		} else {
			if (q.size()) {
				int a = q.front();
				if (a != x) res[0] = 0;
				q.pop();
			} else res[0] = 0;
			
			if (stk.size()) {
				int b = stk.top();
				if (b != x) res[1] = 0;
				stk.pop();
			} else res[1] = 0;
			
			if (big.size()) {
				int c = big.top();
				if (c != x) res[2] = 0;
				big.pop();
			} else res[2] = 0;
			
			if (small.size()) {
				int d = small.top();
				if (d != x) res[3] = 0;
				small.pop();
			} else res[3] = 0;
		}
	}
	if (res[0]) cout << "Yes\n";
	else cout << "No\n";
	if (res[1]) cout << "Yes\n";
	else cout << "No\n";
	if (res[2]) cout << "Yes\n";
	else cout << "No\n";
	if (res[3]) cout << "Yes\n";
	else cout << "No\n";
}

int main() {
	int T = 1;
	//T = rd();
	while (T -- ) {
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3412kb

input:

6
1 1
1 2
1 3
2 1
2 2
2 3

output:

Yes
No
No
Yes

result:

ok 4 lines

Test #2:

score: 0
Accepted
time: 22ms
memory: 3388kb

input:

100000
1 49
1 59
2 49
1 98
2 59
2 98
1 95
1 34
1 64
2 95
1 18
1 44
1 7
1 78
2 34
2 64
2 18
1 37
2 44
1 89
2 7
1 2
1 21
2 78
2 37
1 90
1 75
1 50
1 33
1 70
1 32
2 89
2 2
1 49
2 21
1 46
2 90
1 3
2 75
1 50
1 37
1 24
1 88
1 78
2 50
1 22
1 73
1 95
1 100
2 33
1 28
1 62
1 25
2 70
1 90
2 32
1 31
2 49
2 46
2 ...

output:

Yes
No
No
No

result:

ok 4 lines

Test #3:

score: 0
Accepted
time: 23ms
memory: 3500kb

input:

100000
1 78
1 47
1 9
2 9
2 47
2 78
1 67
1 58
1 6
2 6
1 60
1 5
2 5
2 60
1 100
2 100
1 76
1 28
1 81
1 40
1 5
2 5
2 40
1 39
1 13
1 82
2 82
2 13
1 19
2 19
2 39
1 47
1 25
2 25
2 47
2 81
2 28
2 76
2 58
2 67
1 13
2 13
1 39
2 39
1 72
2 72
1 88
1 84
2 84
2 88
1 100
2 100
1 2
2 2
1 91
1 20
2 20
1 25
1 37
2 37...

output:

No
Yes
No
No

result:

ok 4 lines

Test #4:

score: 0
Accepted
time: 22ms
memory: 3452kb

input:

100000
1 99
1 79
2 79
1 90
2 90
2 99
1 43
1 40
1 61
2 40
2 43
2 61
1 98
1 70
1 65
2 65
2 70
2 98
1 64
2 64
1 64
1 12
1 57
1 54
1 69
1 19
1 67
1 99
1 42
1 25
1 88
2 12
2 19
1 50
1 45
1 60
1 55
1 14
1 49
1 55
2 14
1 87
2 25
1 14
2 14
1 37
1 20
2 20
2 37
2 42
2 45
2 49
1 82
1 39
1 80
1 76
1 7
2 7
1 19
...

output:

No
No
No
Yes

result:

ok 4 lines

Test #5:

score: 0
Accepted
time: 22ms
memory: 3392kb

input:

100000
1 83
2 83
1 84
1 49
1 12
1 29
2 84
2 49
1 3
2 29
2 12
2 3
1 24
1 46
1 13
2 46
2 24
2 13
1 66
1 92
2 92
2 66
1 37
1 50
1 16
1 90
2 90
1 92
2 92
1 38
2 50
1 24
1 85
1 13
2 85
2 38
1 53
1 46
1 7
1 43
1 16
1 28
2 53
1 56
1 59
2 59
2 56
2 46
2 43
1 31
1 64
1 3
2 64
1 46
2 46
2 37
2 31
1 71
2 71
1 ...

output:

No
No
Yes
No

result:

ok 4 lines

Test #6:

score: 0
Accepted
time: 27ms
memory: 3468kb

input:

100000
1 -2147483648
2 -2147483648
1 -2147483648
1 1
1 1
2 -2147483648
2 1
1 -2147483648
2 -2147483648
1 -1
1 1
2 -1
1 1
1 -2147483648
2 -2147483648
1 1
1 -2147483648
2 -2147483648
2 1
2 1
1 -1
2 -1
1 -1
2 -1
2 1
2 1
1 -2147483648
2 -2147483648
1 1
2 1
1 -1
2 -1
1 1
2 1
1 1
2 1
1 -2147483648
2 -2147...

output:

No
No
No
Yes

result:

ok 4 lines

Test #7:

score: 0
Accepted
time: 18ms
memory: 3504kb

input:

100000
1 1
2 1
1 1
2 1
2 1
1 1
1 1
1 1
1 1
1 1
1 1
2 1
2 1
1 1
2 1
2 1
1 1
2 1
2 1
1 1
1 1
2 1
1 1
2 1
2 1
2 1
1 1
1 1
1 1
2 1
2 1
1 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
1 1
1 1
1 1
1 1
1 1
1 1
2 1
2 1
2 1
2 1
1 1
1 1
2 1
2 1
2 1
1 1
1 1
1 1
2 1
1 1
2 1
1 1
1 1
1 1
2 1
1 1
2 1
2 1
2 1
1 1
1 1
2 1
1 1
1 1
2...

output:

No
No
No
No

result:

ok 4 lines