結果

問題 No.1546 [Cherry 2nd Tune D] 思ったよりも易しくない
ユーザー midri1784
提出日時 2021-06-11 23:07:30
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 120 ms / 2,000 ms
コード長 4,098 bytes
コンパイル時間 1,756 ms
コンパイル使用メモリ 171,468 KB
実行使用メモリ 8,192 KB
最終ジャッジ日時 2024-12-15 02:07:55
合計ジャッジ時間 9,337 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 53
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
typedef unsigned long long ui64;
typedef vector<i64> vi;
typedef vector<vi> vvi;
typedef pair<i64, i64> pi;
#define pb push_back
#define sz(a) i64((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)
inline void RI(i64 &i) {scanf("%lld", &(i));}
inline void RVI(vi &v) { for(i64 i=0;i<sz(v);++i) { RI(v[i]); } }
inline void RVVI(vvi &vv) { for(i64 i=0;i<sz(vv);++i) { RVI(vv[i]); } }
inline void WI(const i64 &i) {printf("%lld\n", i);}
inline void WVI(const vi &v, char sep=' ') { for(i64 i=0;i<sz(v);++i) { if(i != 0){ printf("%c", sep); } printf("%lld", v[i]);} printf("\n"); }
inline void WS(const string &s) { printf("%s\n", s.c_str()); }
inline void WB(bool b, const string &yes, const string &no) { if(b){ WS(yes);} else { WS(no);} }
inline void YESNO(bool b) { WB(b, "YES", "NO"); }
inline void YesNo(bool b) { WB(b, "Yes", "No"); }
#define BUF_LENGTH 1000000
inline void RS(string &s) {static char buf[BUF_LENGTH]; scanf("%s", buf); s = buf;}
template<typename T> inline bool IN(T &S, const typename T::key_type &key) {
return S.find(key) != S.end();
}
template<typename T> inline bool ON(const T &b, i64 idx) {
return ((T(1) << idx) & b) != 0;
}
template<long long M, typename T=long long>
struct modint {
modint(T v=T(0)) : val((v >= 0 ? v : (M - ((-v) % M))) % M) {}
using this_type = modint<M, T>;
T val;
this_type operator++(int) {
this_type ret = *this;
val++; val %= M;
return ret;
}
this_type operator--(int) {
this_type ret = *this;
val += M-1; val %= M;
return ret;
}
this_type &operator++() {
val++; val %= M;
return *this;
}
this_type &operator--() {
val += M-1; val %= M;
return *this;
}
this_type operator+() const { return *this; }
this_type operator-() const { return this_type(M-val); };
friend this_type operator+(const this_type &lhs, const this_type &rhs) {
return this_type(lhs) += rhs;
}
friend this_type operator-(const this_type &lhs, const this_type &rhs) {
return this_type(lhs) -= rhs;
}
friend this_type operator*(const this_type &lhs, const this_type &rhs) {
return this_type(lhs) *= rhs;
}
friend this_type operator/(const this_type &lhs, const this_type &rhs) {
return this_type(lhs) /= rhs;
}
this_type pow(long long b) const {
this_type ret = 1, a = *this;
while(b != 0) {
if(b % 2 != 0) {
ret *= a;
}
b /= 2;
a = a * a;
}
return ret;
}
this_type inv() const {
return pow(M-2);
}
this_type& operator+=(const this_type &rhs) {
val += rhs.val; val %= M; return *this;
}
this_type& operator-=(const this_type &rhs) {
val += M - rhs.val; val %= M; return *this;
}
this_type& operator*=(const this_type &rhs) {
val *= rhs.val; val %= M; return *this;
}
this_type& operator/=(const this_type &rhs) {
*this *= rhs.inv(); return *this;
}
friend bool operator==(const this_type &lhs, const this_type &rhs) {
return lhs.val == rhs.val;
}
friend bool operator!=(const this_type &lhs, const this_type &rhs) {
return lhs.val != rhs.val;
}
T mod() const {return M;}
};
using mi = modint<998244353>;
using vmi = vector<mi>;
using vvmi = vector<vmi>;
inline mi S0(mi v) {
return v;
}
mi inv_2 = mi(2).inv();
mi inv_6 = mi(6).inv();
inline mi S1(mi v) {
return v * (v + 1) * inv_2;
}
inline mi S2(mi v) {
return v * (v + 1) * (2 * v + 1) * inv_6;
}
inline mi S3(mi v) {
mi s = S1(v);
return s * s;
}
inline mi F(mi v, mi L) {
return (- S3(v) + (L - 3) * S2(v) + (3 * L - 2) * S1(v) + 2 * L * S0(v)) * inv_2;
}
inline mi G(mi l, mi r, mi L) {
return F(r-1, L) - F(l-1, L);
}
int main(int argc, char *argv[]) {
i64 i, j, k;
i64 N; cin >> N;
vi T(N), V(N);
mi L = 0;
REP(0, N, i) {
RI(T[i]); RI(V[i]);
L += T[i];
}
mi ans = 0;
mi l = 0;
REP(0, N, i) {
//cerr << G(l, l + T[i], V[i]).val << endl;
ans += G(l, l + T[i], L) * mi(V[i]);
l += T[i];
}
WI(ans.val);
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0