QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#21657#2815. 组合数据结构问题lindongli2004#AC ✓20ms9672kbC++141.5kb2022-03-07 18:52:102022-05-08 03:47:16

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-08 03:47:16]
  • 评测
  • 测评结果:AC
  • 用时:20ms
  • 内存:9672kb
  • [2022-03-07 18:52:10]
  • 提交

answer

// by iodwad
#include <cstdio>
#include <iostream>
#include <queue>

#define int long long

using namespace std;

const int MAXN = 2e5;

int n;
int opt[MAXN + 5], v[MAXN + 5];

bool check_queue() {
  int hd = 1, tl = 0;
  static int que[MAXN + 5];
  for (int i = 1; i <= n; ++i) {
    if (opt[i] == 1) que[++tl] = v[i];
    else {
      if (hd > tl || que[hd] != v[i]) return false;
      ++hd;
    }
  }
  return true;
}

bool check_stack() {
  int tl = 0;
  static int stack[MAXN + 5];
  for (int i = 1; i <= n; ++i) {
    if (opt[i] == 1) stack[++tl] = v[i];
    else {
      if (!tl || stack[tl] != v[i]) return false;
      --tl;
    }
  }
  return true;
}

bool check_bigh() {
  static priority_queue<int> q;
  for (int i = 1; i <= n; ++i) {
    if (opt[i] == 1) q.push(v[i]);
    else {
      if (q.empty() || q.top() != v[i]) return false;
      q.pop();
    }
  }
  return true;
}

bool check_smallh() {
  static priority_queue<int> q;
  for (int i = 1; i <= n; ++i) {
    if (opt[i] == 1) q.push(-v[i]);
    else {
      if (q.empty() || q.top() != -v[i]) return false;
      q.pop();
    }
  }
  return true;
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> opt[i] >> v[i];
  puts(check_queue() ? "Yes" : "No");
  puts(check_stack() ? "Yes" : "No");
  puts(check_bigh() ? "Yes" : "No");
  puts(check_smallh() ? "Yes" : "No");
  return 0;
}
 

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 7704kb

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: 11ms
memory: 8484kb

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: 15ms
memory: 8948kb

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: 18ms
memory: 9672kb

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: 11ms
memory: 7980kb

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: 20ms
memory: 8500kb

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: 3ms
memory: 7964kb

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