提出 #76054668


ソースコード 拡げる

#include <bits/stdc++.h>
#define int long long
#define ll long long
#define ull unsigned long long
#define inf 4e18
#define eps 1e-9
#define il inline
#define ls 2*k
#define rs 2*k+1
using namespace std;
const int N=1e6+5,M=250005;
const int mod=998244353;
inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*f;
}
int n,q,a[N];
struct BIT{
    int f[N];
    inline void add(int p,int v){
        for(;p<=1e6;p+=(p&-p)) f[p]+=v;
        return ;
    }
    inline int query(int p){
        int res=0;
        for(;p;p-=(p&-p)) res+=f[p];
        return res;
    }
}tr;
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int tc=1;
	while(tc--){
		cin>>n>>q; 
		int now=1;
		tr.add(1,n);
		for(int i=1;i<=n;i++) a[i]=1;
		while(q--){
			int op,x;
			cin>>op>>x;
			if(op==1){
				tr.add(a[x],-1);
				a[x]++;
				tr.add(a[x],1);
				if(tr.query(now)==0) now++;
//				cout<<x<<' '<<a[x]<<'\n';
			}
			else{
				x+=now;
				cout<<(tr.query(1e6)-tr.query(x-1))<<'\n';
//				cout<<x<<"---\n";
			}
		}
	}
	return 0;
}
/*
input: 
1
3 4 1
1 2 3
3 3 4 7 
6
output:
14

从大到小按位考虑,则如果能在不会让前面取不到的情况下取到,那么一定要操作。 
*/

提出情報

提出日時
問題 C - Drop Blocks
ユーザ Limingxuan
言語 C++23 (GCC 15.2.0)
得点 300
コード長 1430 Byte
結果 AC
実行時間 30 ms
メモリ 6108 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 300 / 300
結果
AC × 1
AC × 50
セット名 テストケース
Sample example_00.txt
All example_00.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, hand_12.txt, hand_13.txt, hand_14.txt, hand_15.txt, hand_16.txt, hand_17.txt, hand_18.txt, hand_19.txt, hand_20.txt, hand_21.txt, hand_22.txt, hand_23.txt, hand_24.txt, hand_25.txt, hand_26.txt, hand_27.txt, hand_28.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt
ケース名 結果 実行時間 メモリ
example_00.txt AC 1 ms 3704 KiB
hand_00.txt AC 28 ms 5840 KiB
hand_01.txt AC 28 ms 5904 KiB
hand_02.txt AC 27 ms 3716 KiB
hand_03.txt AC 21 ms 3716 KiB
hand_04.txt AC 25 ms 4824 KiB
hand_05.txt AC 24 ms 3684 KiB
hand_06.txt AC 21 ms 3740 KiB
hand_07.txt AC 18 ms 5972 KiB
hand_08.txt AC 20 ms 3672 KiB
hand_09.txt AC 20 ms 4824 KiB
hand_10.txt AC 20 ms 4228 KiB
hand_11.txt AC 19 ms 5972 KiB
hand_12.txt AC 19 ms 6092 KiB
hand_13.txt AC 23 ms 3532 KiB
hand_14.txt AC 26 ms 4796 KiB
hand_15.txt AC 25 ms 4380 KiB
hand_16.txt AC 1 ms 3492 KiB
hand_17.txt AC 24 ms 6044 KiB
hand_18.txt AC 17 ms 5836 KiB
hand_19.txt AC 17 ms 6008 KiB
hand_20.txt AC 18 ms 6108 KiB
hand_21.txt AC 28 ms 5968 KiB
hand_22.txt AC 30 ms 5976 KiB
hand_23.txt AC 21 ms 5964 KiB
hand_24.txt AC 23 ms 6044 KiB
hand_25.txt AC 2 ms 5904 KiB
hand_26.txt AC 2 ms 5988 KiB
hand_27.txt AC 4 ms 6020 KiB
hand_28.txt AC 21 ms 4300 KiB
random_00.txt AC 24 ms 4940 KiB
random_01.txt AC 22 ms 3740 KiB
random_02.txt AC 25 ms 3668 KiB
random_03.txt AC 25 ms 3692 KiB
random_04.txt AC 26 ms 4172 KiB
random_05.txt AC 21 ms 4292 KiB
random_06.txt AC 25 ms 3532 KiB
random_07.txt AC 27 ms 3668 KiB
random_08.txt AC 25 ms 3724 KiB
random_09.txt AC 25 ms 3812 KiB
random_10.txt AC 25 ms 3932 KiB
random_11.txt AC 25 ms 3600 KiB
random_12.txt AC 27 ms 3668 KiB
random_13.txt AC 25 ms 3740 KiB
random_14.txt AC 26 ms 3788 KiB
random_15.txt AC 20 ms 5396 KiB
random_16.txt AC 24 ms 3660 KiB
random_17.txt AC 21 ms 5288 KiB
random_18.txt AC 27 ms 3832 KiB
random_19.txt AC 26 ms 3928 KiB