QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#854983 | #8704. 排队 | _Alexande_ | 0 | 220ms | 10448kb | C++14 | 3.9kb | 2025-01-12 11:49:03 | 2025-01-12 11:49:03 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fir first
#define sec second
#define mkp make_pair
#define pb push_back
#define lep( i, l, r ) for ( int i = ( l ); i <= ( r ); ++ i )
#define rep( i, r, l ) for ( int i = ( r ); i >= ( l ); -- i )
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair < int, int > pii;
char _c; bool _f; template < class type > inline void read ( type &x ) {
_f = 0, x = 0;
while ( _c = getchar (), !isdigit ( _c ) ) if ( _c == '-' ) _f = 1;
while ( isdigit ( _c ) ) x = x * 10 + _c - '0', _c = getchar (); if ( _f ) { x = -x; }
}
template < class type > inline void chkmin ( type &x, type y ) { x = ( x <= y ? x : y ); }
template < class type > inline void chkmax ( type &x, type y ) { x = ( x >= y ? x : y ); }
mt19937 rnd ( time ( 0 ) );
const int N = 3e5 + 5;
int n, m, rt;
struct Node {
int ls, rs, fa, val, siz, key;
} tree[N];
void pushup ( int node ) {
tree[node].val = min ( min ( tree[tree[node].ls].val, tree[tree[node].rs].val ), tree[node].val );
tree[node].siz = tree[tree[node].ls].siz + tree[tree[node].rs].siz + 1;
}
void split ( int node, int &r1, int &r2, int siz ) {
if ( !node ) {
r1 = r2 = 0;
return ;
}
if ( tree[tree[node].ls].siz + 1 <= siz ) {
r1 = node, tree[tree[node].rs].fa = 0;
split ( tree[node].rs, tree[node].rs, r2, siz - tree[tree[node].ls].siz - 1 );
if ( tree[node].rs ) {
tree[tree[node].rs].fa = node;
}
}
else {
r2 = node, tree[tree[node].ls].fa = 0;
split ( tree[node].ls, r1, tree[node].ls, siz );
if ( tree[node].ls ) {
tree[tree[node].ls].fa = node;
}
}
}
int merge ( int x, int y ) {
if ( !x || !y ) {
return x + y;
}
if ( tree[x].key < tree[y].key ) {
tree[tree[x].rs].fa = 0;
tree[x].rs = merge ( tree[x].rs, y );
if ( tree[x].rs ) {
tree[tree[x].rs].fa = x;
}
pushup ( x );
return x;
}
else {
tree[tree[y].ls].fa = 0;
tree[y].ls = merge ( x, tree[y].ls );
if ( tree[y].ls ) {
tree[tree[y].ls].fa = y;
}
pushup ( y );
return y;
}
}
int rnk ( int node ) {
int res = tree[tree[node].ls].siz + 1;
while ( node != rt ) {
if ( tree[tree[node].fa].rs == node ) {
res += tree[tree[tree[node].fa].ls].siz + 1;
}
node = tree[node].fa;
}
return res;
}
int find ( int x, int v ) {
if ( !x ) {
return 0;
}
if ( v > tree[tree[x].ls].val || v > x ) {
return find ( tree[x].ls, v );
}
return tree[tree[x].ls].siz + 1 + find ( tree[x].rs, v );
}
int newnode ( int x ) {
tree[x].val = x, tree[x].key = rnd (), tree[x].siz = 1;
return x;
}
void insert ( int x ) {
x = rnk ( x );
int t1, t2;
split ( rt, t1, t2, x );
rt = merge ( merge ( t1, newnode ( ++ n ) ), t2 );
}
void Solve () {
ios :: sync_with_stdio ( false );
cin.tie ( 0 ), cout.tie ( 0 );
int id;
cin >> id >> m;
tree[rt].val = m + 1;
while ( m -- ) {
int op;
cin >> op;
if ( op == 1 ) {
int x;
cin >> x;
++n,tree[n].val = n, tree[n].siz = 1, tree[n].key = rnd();
if (x) x = rnk(x);
int a, b;
split(rt, x, a, b);
rt = merge(merge(a, n), b);
}
else if ( op == 2 ) {
int x, y;
cin >> x >> y;
int a, b, c;
split ( rt, a, b, rnk ( x ) - 1 );
split ( b, b, c, find ( b, x ) );
rt = merge ( a, c );
int d, e, f;
split ( rt, d, e, y == 0 ? 0 : rnk ( y ) );
split ( e, e, f, find ( e, x ) );
rt = merge ( merge ( d, e ), merge ( b, f ) );
}
else {
int x;
cin >> x;
cout << rnk ( x ) << '\n';
}
}
}
signed main () {
#ifdef judge
freopen ( "Code.in", "r", stdin );
freopen ( "Code.out", "w", stdout );
freopen ( "Code.err", "w", stderr );
#endif
Solve ();
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 4
Accepted
time: 0ms
memory: 3664kb
input:
0 8 1 0 1 1 1 2 3 2 2 2 0 3 1 3 2 3 3
output:
2 3 1 2
result:
ok 4 lines
Test #2:
score: 0
Wrong Answer
time: 1ms
memory: 3812kb
input:
0 485 1 0 2 1 0 2 1 0 3 1 3 1 1 0 1 1 3 3 2 3 2 2 2 1 2 2 1 2 2 0 3 1 3 1 3 1 1 0 2 3 0 1 2 3 3 1 3 2 3 2 1 1 2 2 0 1 3 2 3 0 2 1 0 1 1 2 8 6 2 3 0 3 3 2 4 1 1 4 3 2 1 0 1 5 1 4 2 3 2 2 7 4 3 5 1 7 1 8 2 7 5 3 14 3 2 2 6 2 3 13 1 0 3 11 1 13 3 1 3 4 1 4 2 15 0 2 15 9 2 17 16 3 13 1 17 2 17 12 3 3 3 ...
output:
1 1 3 3 3 3 1 1 2 10 14 1 16 14 9 10 16 8 4 9 3 8 11 7 15 28 13 47 46 18 28 47 2 11 39 38 35 36 56 1 24 65 75 64 72 19 59 75 83 18 100 88 46 49 13 36 12 93 13 118 56 3 128 83 38 22 1 128 4 86 7 37 68 133 134 50 54 75 102 2 121 168 145 38 107 44 152 72 113 29 51 160 139 163 148 90 55 94 70 142 44 24 ...
result:
wrong answer 7th lines differ - expected: '2', found: '1'
Subtask #2:
score: 0
Wrong Answer
Test #5:
score: 0
Wrong Answer
time: 77ms
memory: 10448kb
input:
1 298913 1 0 3 1 3 1 3 1 3 1 3 1 1 0 1 0 3 3 1 2 1 2 3 5 3 5 1 1 1 3 1 4 3 3 1 3 1 6 3 7 3 2 3 5 3 8 3 2 1 8 3 3 1 4 3 2 3 7 1 3 3 4 1 10 3 14 3 13 1 12 3 4 1 8 1 15 1 16 3 9 3 14 3 10 3 8 3 7 1 16 1 15 3 16 3 13 1 19 3 13 3 1 3 14 1 18 1 22 3 8 1 17 3 18 3 9 1 18 3 9 3 1 1 20 3 11 3 5 3 2 3 22 1 22...
output:
1 1 1 1 1 3 5 5 3 7 2 5 8 2 3 2 7 4 14 13 4 9 14 10 8 7 16 13 13 1 14 8 18 9 9 1 11 5 2 22 2 21 23 6 29 30 14 7 3 29 32 17 18 11 31 2 32 14 14 12 33 14 31 15 6 38 19 24 30 12 44 10 22 34 1 33 11 19 47 20 33 18 53 8 21 36 36 3 22 3 53 15 23 38 41 13 12 16 45 21 67 23 21 51 44 13 13 5 7 36 64 68 48 36...
result:
wrong answer 6th lines differ - expected: '1', found: '3'
Subtask #3:
score: 0
Wrong Answer
Test #20:
score: 0
Wrong Answer
time: 75ms
memory: 8944kb
input:
2 298235 1 0 1 1 3 2 1 0 1 3 3 4 3 3 3 3 3 2 3 4 3 2 3 3 1 2 3 3 1 4 1 2 1 1 3 5 3 8 1 5 1 9 3 10 3 8 3 10 3 5 3 8 3 5 1 2 1 9 3 5 3 7 3 12 3 3 1 6 3 4 3 3 3 11 3 8 3 9 3 7 3 6 3 4 1 12 1 11 3 13 3 13 1 11 3 16 3 6 3 14 3 9 3 5 3 13 1 9 1 17 3 16 3 13 3 5 3 15 3 8 3 4 3 13 1 18 3 15 3 16 3 19 3 4 1 ...
output:
2 4 3 3 2 4 2 3 3 5 8 10 8 10 5 8 5 5 7 12 3 4 3 11 8 9 7 6 4 13 13 16 6 14 9 5 13 16 13 5 15 8 4 13 15 16 19 4 17 7 7 2 6 6 15 12 2 1 13 4 21 1 9 19 8 24 20 1 14 13 9 7 2 21 24 8 23 16 23 23 20 6 18 17 25 23 14 20 12 25 18 21 7 22 11 11 7 9 10 11 20 10 29 20 13 3 17 24 10 17 36 2 20 18 18 22 30 39 ...
result:
wrong answer 2nd lines differ - expected: '2', found: '4'
Subtask #4:
score: 0
Wrong Answer
Test #35:
score: 0
Wrong Answer
time: 220ms
memory: 8756kb
input:
3 299743 1 0 1 1 3 1 1 2 3 2 1 0 3 3 3 2 3 1 3 2 2 2 1 3 3 3 3 3 4 3 1 3 2 3 2 2 1 0 3 2 3 1 3 1 1 0 3 2 1 2 1 1 3 2 2 5 2 1 6 1 0 2 5 2 1 7 3 8 3 5 3 5 2 7 5 2 9 4 3 5 3 8 2 6 2 2 3 0 2 2 0 1 1 2 3 1 1 8 2 7 0 3 3 1 12 2 13 9 1 5 2 2 1 2 14 13 1 12 2 1 0 2 12 10 2 15 12 1 0 1 6 3 6 2 3 2 2 17 6 3 4...
output:
1 2 3 2 1 2 3 3 4 1 2 2 2 1 1 2 2 10 5 5 5 12 14 30 19 36 23 25 25 39 43 13 52 28 28 59 51 31 51 25 41 21 14 50 59 50 45 52 61 63 15 63 29 70 16 41 70 70 86 91 46 75 24 38 60 5 58 92 88 96 38 61 34 81 32 66 39 64 49 25 6 104 124 34 39 89 62 116 103 81 117 89 113 55 118 11 11 122 128 45 55 89 104 88 ...
result:
wrong answer 3rd lines differ - expected: '4', found: '3'
Subtask #5:
score: 0
Skipped
Dependency #1:
0%