提出 #48393042


ソースコード 拡げる

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5+5;
struct node{
	int l,r,dat,lazy1=1,lazy2;
}t[N<<2];
int n,m,mod;
int ksm(int x,int y)
{
	int ret=1,bace=x;
	while(y)
	{
		if(y&1)ret=ret*bace%mod;
		bace=bace*bace%mod;
		y>>=1;
	}
	return ret;
}
void build(int p,int l,int r)
{
	t[p].l=l,t[p].r=r;
	if(l==r)return;
	int mid=l+r>>1;
	build(p<<1,l,mid);
	build(p<<1|1,mid+1,r);
}
void pushup(int p)
{
	t[p].dat=(t[p<<1].dat+t[p<<1|1].dat)%mod;
}
void pushdown(int p)
{
	
	t[p<<1].dat=(t[p<<1].dat*t[p].lazy1+(t[p<<1].r-t[p<<1].l+1)*t[p].lazy2%mod)%mod;
	t[p<<1|1].dat=(t[p<<1|1].dat*t[p].lazy1+(t[p<<1|1].r-t[p<<1|1].l+1)*t[p].lazy2%mod)%mod;
	t[p<<1].lazy1=(t[p<<1].lazy1*t[p].lazy1)%mod;
	t[p<<1|1].lazy1=(t[p<<1|1].lazy1*t[p].lazy1)%mod;
	t[p<<1].lazy2=((t[p<<1].lazy2*t[p].lazy1)%mod+t[p].lazy2)%mod;
	t[p<<1|1].lazy2=((t[p<<1|1].lazy2*t[p].lazy1)%mod+t[p].lazy2)%mod;
	t[p].lazy1=1;
	t[p].lazy2=0;
}
void change1(int p,int l,int r,int k)
{
	if(l<=t[p].l&&r>=t[p].r)
	{
		t[p].dat=(t[p].dat*k)%mod;
		t[p].lazy1=(t[p].lazy1*k)%mod;
		t[p].lazy2=(t[p].lazy2*k)%mod;
		return;
	}
	pushdown(p);
	int mid=t[p].l+t[p].r>>1;
	if(l<=mid)change1(p<<1,l,r,k);
	if(r>mid)change1(p<<1|1,l,r,k);
	pushup(p);
}
void change2(int p,int l,int r,int k)
{
	if(l<=t[p].l&&r>=t[p].r)
	{
		t[p].dat=(t[p].dat+k*(t[p].r-t[p].l+1)%mod)%mod;
		t[p].lazy2=(t[p].lazy2+k)%mod;
		return;
	}
	pushdown(p);
	int mid=t[p].l+t[p].r>>1;
	if(l<=mid)change2(p<<1,l,r,k);
	if(r>mid)change2(p<<1|1,l,r,k);
	pushup(p);
}
int query(int p,int l,int r)
{
	if(l<=t[p].l&&r>=t[p].r)return t[p].dat;
	pushdown(p);
	int ret=0,mid=t[p].l+t[p].r>>1;
	if(l<=mid)ret=(ret+query(p<<1,l,r))%mod;
	if(r>mid)ret=(ret+query(p<<1|1,l,r))%mod;
	return ret;
}
signed main()
{
	scanf("%lld%lld",&n,&m);
	mod=998244353;
	build(1,1,n);
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%lld",&x);
		change2(1,i,i,x);
	}
	while(m--)
	{
		int l,r,x,inv;
		scanf("%lld%lld%lld",&l,&r,&x);
		inv=ksm(r-l+1,mod-2);
		change1(1,l,r,(r-l)*inv%mod),change2(1,l,r,inv*x%mod);
	}
	for(int i=1;i<=n;i++)printf("%lld ",query(1,i,i));
	return 0;
}

提出情報

提出日時
問題 F - Random Update Query
ユーザ lishujia
言語 C++ 20 (gcc 12.2)
得点 550
コード長 2207 Byte
結果 AC
実行時間 918 ms
メモリ 35128 KiB

コンパイルエラー

Main.cpp: In function ‘void build(long long int, long long int, long long int)’:
Main.cpp:24:18: warning: suggest parentheses around ‘+’ inside ‘>>’ [-Wparentheses]
   24 |         int mid=l+r>>1;
      |                 ~^~
Main.cpp: In function ‘void change1(long long int, long long int, long long int, long long int)’:
Main.cpp:54:23: warning: suggest parentheses around ‘+’ inside ‘>>’ [-Wparentheses]
   54 |         int mid=t[p].l+t[p].r>>1;
      |                 ~~~~~~^~~~~~~
Main.cpp: In function ‘void change2(long long int, long long int, long long int, long long int)’:
Main.cpp:68:23: warning: suggest parentheses around ‘+’ inside ‘>>’ [-Wparentheses]
   68 |         int mid=t[p].l+t[p].r>>1;
      |                 ~~~~~~^~~~~~~
Main.cpp: In function ‘long long int query(long long int, long long int, long long int)’:
Main.cpp:77:29: warning: suggest parentheses around ‘+’ inside ‘>>’ [-Wparentheses]
   77 |         int ret=0,mid=t[p].l+t[p].r>>1;
      |                       ~~~~~~^~~~~~~
Main.cpp: In function ‘int main()’:
Main.cpp:84:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   84 |         scanf("%lld%lld",&n,&m);
      |         ~~~~~^~~~~~~~~~~~~~~~~~
Main.cpp:90:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   90 |                 scanf("%lld",&x);
      |                 ~~~~~^~~~~~~~~~~
Main.cpp:96:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   96 |                 scanf("%lld%lld%lld",&l,&r,&x);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 550 / 550
結果
AC × 3
AC × 39
セット名 テストケース
Sample example0.txt, example1.txt, example2.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, example0.txt, example1.txt, example2.txt
ケース名 結果 実行時間 メモリ
000.txt AC 99 ms 34836 KiB
001.txt AC 637 ms 35004 KiB
002.txt AC 639 ms 34928 KiB
003.txt AC 629 ms 34836 KiB
004.txt AC 674 ms 35000 KiB
005.txt AC 674 ms 35068 KiB
006.txt AC 673 ms 34832 KiB
007.txt AC 386 ms 35064 KiB
008.txt AC 386 ms 34992 KiB
009.txt AC 386 ms 34832 KiB
010.txt AC 898 ms 35064 KiB
011.txt AC 899 ms 35004 KiB
012.txt AC 899 ms 35012 KiB
013.txt AC 888 ms 35124 KiB
014.txt AC 899 ms 34836 KiB
015.txt AC 679 ms 34872 KiB
016.txt AC 251 ms 35004 KiB
017.txt AC 350 ms 34908 KiB
018.txt AC 490 ms 35060 KiB
019.txt AC 452 ms 34832 KiB
020.txt AC 418 ms 34928 KiB
021.txt AC 257 ms 35012 KiB
022.txt AC 261 ms 34936 KiB
023.txt AC 413 ms 35008 KiB
024.txt AC 272 ms 35004 KiB
025.txt AC 911 ms 34928 KiB
026.txt AC 918 ms 34904 KiB
027.txt AC 912 ms 34908 KiB
028.txt AC 913 ms 34908 KiB
029.txt AC 911 ms 34940 KiB
030.txt AC 912 ms 34872 KiB
031.txt AC 910 ms 34836 KiB
032.txt AC 912 ms 35128 KiB
033.txt AC 912 ms 34932 KiB
034.txt AC 912 ms 35008 KiB
035.txt AC 892 ms 35000 KiB
example0.txt AC 11 ms 34928 KiB
example1.txt AC 11 ms 35004 KiB
example2.txt AC 12 ms 35000 KiB