結果

問題 No.1546 [Cherry 2nd Tune D] 思ったよりも易しくない
ユーザー kmjp
提出日時 2021-06-11 23:28:49
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 245 ms / 2,000 ms
コード長 1,492 bytes
コンパイル時間 2,097 ms
コンパイル使用メモリ 195,872 KB
最終ジャッジ日時 2025-01-22 07:05:56
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 53
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------


int N;
ll T[303030],V[303030];
const ll mo=998244353;

ll modpow(ll a, ll n = mo-2) {
	ll r=1;a%=mo;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	ll S=0;
	FOR(i,N) {
		cin>>T[i]>>V[i];
		T[i]%=mo;
		(S+=T[i])%=mo;
	}
	ll L=0;
	ll R=S;
	ll ret=0;
	FOR(i,N) {
		R=(R+mo-T[i])%mo;
		
		ll M=T[i];
		ll k1=M*(M+1)%mo*modpow(2)%mo;
		ll k2=M*(M+1)%mo*(2*M+1)%mo*modpow(6)%mo;
		ll k3=k1*k1%mo;
		
		ll a=L*(L+1)%mo*M%mo;
		a+=k1*(2*L+1)%mo;
		a+=k2%mo;
		a=a*(R+M+1)%mo;
		a-=k1*(L*(L+1)%mo)%mo;
		a-=k2*(2*L+1)%mo;
		a-=k3;
		
		a=(a*modpow(2)%mo+mo)%mo;
		(ret+=V[i]*a%mo)%=mo;
		(L+=T[i])%=mo;
	}
	cout<<ret<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0