提出 #25988358


ソースコード 拡げる

#include<bits/stdc++.h>
using namespace std;
const int M=998244353,N=1000005,iv2=(M+1)/2;
int n,i,q,ch[N*30][2],tree[N*30],tree2[N*30],j,x,y,k=1;
int a[N];
long long ans,s,s2,sum;
void pushup(int i)
{
	tree[i]=(tree[ch[i][0]]+tree[ch[i][1]])%M;
	tree2[i]=tree2[ch[i][0]]+tree2[ch[i][1]];
}
void modify(int i,int l,int r,int x,int y)
{
	if(l==r)
	{
		s2+=tree2[i];
		tree[i]=(tree[i]+l*y)%M;
		tree2[i]+=y;
		if(y==-1)
			--s2;
		ans=(ans+s2*l*y+s*y)%M;
		return;
	}
	int mid=l+r>>1;
	if(mid>=x)
	{
		if(!ch[i][0])
			ch[i][0]=++k;
		s+=tree[ch[i][1]];
		modify(ch[i][0],l,mid,x,y);
	}
	else
	{
		if(!ch[i][1])
			ch[i][1]=++k;
		s2+=tree2[ch[i][0]];
		modify(ch[i][1],mid+1,r,x,y);
	}
	pushup(i);
}
int main(){
	scanf("%d %d",&n,&q);
	for(i=1;i<=n;++i)
	{
		scanf("%d",&a[i]);
		s=s2=0;
		modify(1,1,1000000000,a[i],1);
		sum+=a[i];
		//cout<<ans<<endl;
	}
	while(q--)
	{
		scanf("%d %d",&x,&y);
		s=s2=0;
		modify(1,1,1000000000,a[x],-1);
		sum-=a[x];
		a[x]=y;
		s=s2=0;
		modify(1,1,1000000000,a[x],1);
		sum+=a[x];
		sum%=M;
		printf("%lld\n",((ans-sum*(n-1)%M*iv2)%M+M)%M);
	}
}

提出情報

提出日時
問題 E - Infinite Operations
ユーザ CY_WIN_IOI_GOLD
言語 C++ (GCC 9.2.1)
得点 800
コード長 1148 Byte
結果 AC
実行時間 905 ms
メモリ 115404 KiB

コンパイルエラー

./Main.cpp: In function ‘void modify(int, int, int, int, int)’:
./Main.cpp:24:11: warning: suggest parentheses around ‘+’ inside ‘>>’ [-Wparentheses]
   24 |  int mid=l+r>>1;
      |          ~^~
./Main.cpp: In function ‘int main()’:
./Main.cpp:42:7: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   42 |  scanf("%d %d",&n,&q);
      |  ~~~~~^~~~~~~~~~~~~~~
./Main.cpp:45:8: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   45 |   scanf("%d",&a[i]);
      |   ~~~~~^~~~~~~~~~~~
./Main.cpp:53:8: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   53 |   scanf("%d %d",&x,&y);
      |   ~~~~~^~~~~~~~~~~~~~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 800 / 800
結果
AC × 2
AC × 52
セット名 テストケース
Sample 01_sample_01.txt, 01_sample_02.txt
All 01_sample_01.txt, 01_sample_02.txt, 02_small_01.txt, 02_small_02.txt, 02_small_03.txt, 02_small_04.txt, 02_small_05.txt, 02_small_06.txt, 02_small_07.txt, 02_small_08.txt, 02_small_09.txt, 03_rand_01.txt, 03_rand_02.txt, 03_rand_03.txt, 03_rand_04.txt, 03_rand_05.txt, 03_rand_06.txt, 03_rand_07.txt, 03_rand_08.txt, 03_rand_09.txt, 03_rand_10.txt, 03_rand_11.txt, 03_rand_12.txt, 03_rand_13.txt, 03_rand_14.txt, 03_rand_15.txt, 03_rand_16.txt, 03_rand_17.txt, 03_rand_18.txt, 03_rand_19.txt, 03_rand_20.txt, 03_rand_21.txt, 03_rand_22.txt, 03_rand_23.txt, 03_rand_24.txt, 03_rand_25.txt, 03_rand_26.txt, 03_rand_27.txt, 03_rand_28.txt, 03_rand_29.txt, 03_rand_30.txt, 04_rand_dense_01.txt, 04_rand_dense_02.txt, 04_rand_dense_03.txt, 04_rand_dense_04.txt, 04_rand_dense_05.txt, 04_rand_dense_06.txt, 04_rand_dense_07.txt, 04_rand_dense_08.txt, 04_rand_dense_09.txt, 04_rand_dense_10.txt, 05_handmade_01.txt
ケース名 結果 実行時間 メモリ
01_sample_01.txt AC 13 ms 3724 KiB
01_sample_02.txt AC 1 ms 3712 KiB
02_small_01.txt AC 2 ms 3616 KiB
02_small_02.txt AC 2 ms 3728 KiB
02_small_03.txt AC 2 ms 3628 KiB
02_small_04.txt AC 2 ms 3616 KiB
02_small_05.txt AC 2 ms 3612 KiB
02_small_06.txt AC 2 ms 3676 KiB
02_small_07.txt AC 1 ms 3612 KiB
02_small_08.txt AC 2 ms 3700 KiB
02_small_09.txt AC 2 ms 3676 KiB
03_rand_01.txt AC 831 ms 103496 KiB
03_rand_02.txt AC 506 ms 67204 KiB
03_rand_03.txt AC 583 ms 73612 KiB
03_rand_04.txt AC 569 ms 72492 KiB
03_rand_05.txt AC 713 ms 89680 KiB
03_rand_06.txt AC 905 ms 115404 KiB
03_rand_07.txt AC 733 ms 92084 KiB
03_rand_08.txt AC 734 ms 92424 KiB
03_rand_09.txt AC 552 ms 70948 KiB
03_rand_10.txt AC 728 ms 97380 KiB
03_rand_11.txt AC 582 ms 79772 KiB
03_rand_12.txt AC 631 ms 84944 KiB
03_rand_13.txt AC 637 ms 86148 KiB
03_rand_14.txt AC 700 ms 94232 KiB
03_rand_15.txt AC 458 ms 65108 KiB
03_rand_16.txt AC 502 ms 69444 KiB
03_rand_17.txt AC 849 ms 113432 KiB
03_rand_18.txt AC 714 ms 89968 KiB
03_rand_19.txt AC 779 ms 96828 KiB
03_rand_20.txt AC 634 ms 80732 KiB
03_rand_21.txt AC 848 ms 110480 KiB
03_rand_22.txt AC 552 ms 75812 KiB
03_rand_23.txt AC 772 ms 101888 KiB
03_rand_24.txt AC 641 ms 86164 KiB
03_rand_25.txt AC 816 ms 107636 KiB
03_rand_26.txt AC 847 ms 112940 KiB
03_rand_27.txt AC 781 ms 103900 KiB
03_rand_28.txt AC 613 ms 83656 KiB
03_rand_29.txt AC 648 ms 87368 KiB
03_rand_30.txt AC 579 ms 79168 KiB
04_rand_dense_01.txt AC 336 ms 4376 KiB
04_rand_dense_02.txt AC 335 ms 4104 KiB
04_rand_dense_03.txt AC 311 ms 4500 KiB
04_rand_dense_04.txt AC 314 ms 4160 KiB
04_rand_dense_05.txt AC 330 ms 4104 KiB
04_rand_dense_06.txt AC 285 ms 4008 KiB
04_rand_dense_07.txt AC 300 ms 3808 KiB
04_rand_dense_08.txt AC 393 ms 4716 KiB
04_rand_dense_09.txt AC 307 ms 3780 KiB
04_rand_dense_10.txt AC 386 ms 4492 KiB
05_handmade_01.txt AC 322 ms 4896 KiB