QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#604530#7627. Phonyucup-team3160#WA 2ms8076kbC++144.3kb2024-10-02 11:49:472024-10-02 11:49:48

Judging History

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

  • [2024-10-02 11:49:48]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:8076kb
  • [2024-10-02 11:49:47]
  • 提交

answer

# include <bits/stdc++.h>

using namespace std ;

int n , m ;
typedef long long ll ;
ll k ;
ll a[500005] ;
struct node
{
	int l , r ;
	int lson , rson , sum ;
} seg[10000005] ;
int idx ;
void pushup( int id )
{
	seg[id].sum = seg[seg[id].lson].sum + seg[seg[id].rson].sum ;
}
void update( int id , int x , int v )
{
	if ( seg[id].l == x && seg[id].r == x ) 
	{
		seg[id].sum += v ;
		return ;
	}
	int mid = ( seg[id].l + seg[id].r ) >> 1 ;
	if ( x <= mid )
	{
		if ( ! seg[id].lson ) 
		{
			seg[id].lson = ++idx ;
			seg[idx].l = seg[id].l  , seg[idx].r = mid ;
		}
		update( seg[id].lson , x , v ) ;
	}
	else
	{
		if ( ! seg[id].rson )
		{
			seg[id].rson = ++idx ;
			seg[idx].l = mid + 1 , seg[idx].r = seg[id].r ;
		}
		update( seg[id].rson , x , v ) ;
	}
	pushup( id ) ;
}
int query( int id , int l , int r ) // 查区间和 
{
	if ( l > r ) return 0 ;
	if ( ! id ) return 0 ;
	if ( l <= seg[id].l && seg[id].r <= r ) return seg[id].sum ;
	int mid = ( seg[id].l + seg[id].r ) >> 1 , ans = 0 ;
	if ( l <= mid ) 
	{
		ans += query( seg[id].lson , l , r ) ;
	}
	if ( mid + 1 <= r )
	{
		ans += query( seg[id].rson , l , r ) ;
	}
	return ans ;
}
int merge( int x , int y )
{
	if ( ! x || ! y ) return x + y ;
	if ( seg[x].l == seg[x].r )
	{
		seg[x].sum += seg[y].sum ;
		return x ;
	}
	seg[x].lson = merge( seg[x].lson , seg[y].lson ) ;
	seg[x].rson = merge( seg[x].rson , seg[y].rson ) ;
	pushup( x ) ;
	return x ;
}
int qkth( int id , int k )
{
	if ( ! id ) return 0 ;
	if ( seg[id].l == seg[id].r ) return seg[id].l  ;
	if ( k <= seg[seg[id].rson].sum ) return qkth( seg[id].rson , k ) ;
	return qkth( seg[id].lson , k - seg[seg[id].rson].sum ) ;  
}
int qkth2( int id1 , int id2 , int k )
{
	if ( ! id1 && ! id2 ) return 0 ;
	if ( seg[id1].l == seg[id1].r ) return seg[id1].l  ;
	if ( k <= seg[seg[id2].rson].sum + seg[seg[id1].rson].sum ) return qkth2( seg[id1].rson , seg[id2].rson , k ) ;
	return qkth2( seg[id1].lson , seg[id2].lson , k - ( seg[seg[id2].rson].sum + seg[seg[id1].rson].sum ) ) ;  
}
int rt[500005] ;
ll nums[500005] , cnt ;
struct qe
{
	bool tp ;
	ll v ;
} q[500005] ;
const ll INF = 1e18 ;
int main()
{
	scanf("%d%d" , &n , &m) ;
	scanf("%lld" , &k) ;
	for ( int i = 1 ; i <= n ; i++ ) 
	{
		scanf("%lld" , a + i) ;
		nums[++ cnt] = a[i] / k ;
	}
	sort( a + 1 , a + n + 1 ) ;
	for ( int i = 1 ; i <= m ; i++ )
	{
		char ch ;
		cin >> ch ;
		scanf("%lld" , &q[i].v) ;
		q[i].tp = ( ch == 'C' ) ;
	}
	sort( nums + 1 , nums + cnt + 1 ) ;
	cnt = unique( nums + 1 , nums + cnt + 1 ) - nums - 1 ;
	for ( int i = 1 ; i <= cnt ;i ++ ) 
	{
		rt[i] = ++idx ;
		seg[idx].l = 0 , seg[idx].r = k - 1 ;
	}
	for ( int i = 1 ; i <= n ; i++ )
	{
		int np = lower_bound( nums + 1 , nums + cnt + 1 , a[i] / k ) - nums ;
		update( rt[np] , a[i] % k , 1 ) ;
	}
	nums[0] = -INF ;
	int nst = cnt ;
	ll nv = nums[cnt] , add = 0 ;
	for ( int i = 1 ; i <= m ; i++ )
	{
		if ( q[i].tp == 1 )
		{
			add += q[i].v ;
			while ( true )
			{
				ll dv = add / seg[rt[nst]].sum ;
				if ( nv - dv > nums[nst - 1] ) 
				{
					nv -= dv , add -= dv * seg[rt[nst]].sum ;
					break ;
				}
				else
				{
					add -= ( nv - nums[nst - 1] ) * seg[rt[nst]].sum ;
					rt[nst - 1] = merge( rt[nst] , rt[nst - 1] ) ;
					nv = nums[nst - 1] ;
					nst-- ;
				}
			}
		}
		else
		{
			int x = q[i].v ;
			if ( nv - nums[nst - 1] > 1 )
			{
				if ( x > seg[rt[nst]].sum )
				{
					printf("%lld\n" , a[n - x + 1]) ;
				}
				else
				{
					if ( x <= seg[rt[nst]].sum - add )
					{
						printf("%lld\n" , nv * k + qkth( rt[nst] , add + x )) ;
					}
					else
					{
						printf("%lld\n" , ( nv - 1 ) * k + qkth( rt[nst] , x - ( seg[rt[nst]].sum - add ) ) ) ;
					}
				}
			}
			else
			{
				if ( x > seg[rt[nst]].sum + seg[rt[nst - 1]].sum )
				{
					printf("%lld\n" , a[n - x + 1]) ;
				}
				else
				{
					if ( x <= seg[rt[nst]].sum - add )
					{
						printf("%lld\n" , nv * k + qkth( rt[nst] , add + x )) ;
					}
					else
					{
						int v1 = qkth( rt[nst] , add + 1 ) ;
						if ( seg[rt[nst]].sum + query( rt[nst - 1] , v1 + 1 , k - 1 ) > v1 ) printf("%lld\n" , ( nv - 1 ) * k 
						+ qkth2( rt[nst] , rt[nst - 1] , x - ( seg[rt[nst]].sum - add ) ) ) ;
						else printf("%lld\n" , a[n - x + 1]) ; 
					}
				}
			}
		}
	}
	return 0 ;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 8076kb

input:

3 5 5
7 3 9
A 3
C 1
A 2
C 2
A 3

output:

3
4
-1

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 2ms
memory: 8004kb

input:

5 8 8
294 928 293 392 719
A 4
C 200
A 5
C 10
A 2
C 120
A 1
A 3

output:

294
200
191
0
-2

result:

ok 5 lines

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 5856kb

input:

100 100 233
5101 8001 6561 6329 6305 7745 4321 811 49 1121 3953 8054 8415 9876 6701 4097 6817 6081 495 5521 2389 2042 4721 8119 7441 7840 8001 5756 5561 129 1 5981 4801 7201 8465 7251 6945 5201 5626 3361 5741 3650 7901 2513 8637 3841 5621 9377 101 3661 5105 4241 5137 7501 5561 3581 4901 561 8721 811...

output:

6881
9161
4721
8200
2945
7647
7531
5291
5001
2042
4721
4721
6881
4097
7187
7218
7035
7018
811
8001
2561
6683
6114
6135
3581
5291
1485
5957
5393
2042
5303
5171
5205
4721
5084
4029
4097
4901
4816
4721
4705
2042
4535
4454
4603
4435
3581
4345
115
2042
4284
2042
4274
1485
4326
-17552

result:

wrong answer 20th lines differ - expected: '6752', found: '8001'