QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#854982#8704. 排队_Alexande_0 0ms3672kbC++143.8kb2025-01-12 11:47:182025-01-12 11:47:19

Judging History

This is the latest submission verdict.

  • [2025-01-12 11:47:19]
  • Judged
  • Verdict: 0
  • Time: 0ms
  • Memory: 3672kb
  • [2025-01-12 11:47:18]
  • Submitted

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;
      insert ( x );
    }
    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: 0
Wrong Answer
time: 0ms
memory: 3672kb

input:

0 8
1 0
1 1
1 2
3 2
2 2 0
3 1
3 2
3 3

output:

2
2
1
3

result:

wrong answer 2nd lines differ - expected: '3', found: '2'

Subtask #2:

score: 0
Time Limit Exceeded

Test #5:

score: 0
Time Limit Exceeded

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:


result:


Subtask #3:

score: 0
Time Limit Exceeded

Test #20:

score: 0
Time Limit Exceeded

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:


result:


Subtask #4:

score: 0
Time Limit Exceeded

Test #35:

score: 0
Time Limit Exceeded

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:


result:


Subtask #5:

score: 0
Skipped

Dependency #1:

0%