結果

問題 No.1548 [Cherry 2nd Tune B] 貴方と私とサイクルとモーメント
ユーザー jutamajutama
提出日時 2021-06-12 00:22:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 6,590 bytes
コンパイル時間 3,651 ms
コンパイル使用メモリ 190,932 KB
実行使用メモリ 29,484 KB
最終ジャッジ日時 2023-08-21 15:39:57
合計ジャッジ時間 15,053 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 285 ms
29,160 KB
testcase_33 AC 289 ms
29,288 KB
testcase_34 AC 285 ms
29,184 KB
testcase_35 AC 292 ms
29,244 KB
testcase_36 AC 290 ms
29,400 KB
testcase_37 WA -
testcase_38 AC 285 ms
29,308 KB
testcase_39 AC 286 ms
29,232 KB
testcase_40 AC 283 ms
29,284 KB
testcase_41 AC 284 ms
29,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/all>
#include <bitset>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using namespace atcoder;

typedef long long ll;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;
typedef std::pair<ld, ld> pid;
typedef std::pair<ll, std::string> pls;
typedef std::vector<bool> vb;
typedef std::vector<vb> vvb;
typedef std::vector<int> vi;
typedef std::vector<vi> vvi;
typedef std::vector<vvi> vvvi;
typedef std::vector<vvvi> vvvvi;
typedef std::vector<ll> vl;
typedef std::vector<vl> vvl;
typedef std::vector<vvl> vvvl;
typedef std::vector<vvvl> vvvvl;
typedef std::vector<ld> vd;
typedef std::vector<vd> vvd;
typedef std::vector<std::string> vs;
#define rep(i,n) for(auto i=0; i<n; ++i)
#define repm(i,s,n) for(auto i=s; i<n; ++i)
#define repd(i,n) for(auto i=n-1; i>=0; --i)
#define repdm(i,e,n) for(auto i=n-1; i>=e; --i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

template <class T> inline bool chmax(T& a, T b, int eq = 0) { if (a < b || (a == b && eq)) { a = b; return 1; } return 0; }
template <class T> inline bool chmin(T& a, T b, int eq = 0) { if (a > b || (a == b && eq)) { a = b; return 1; } return 0; }

template <class mint, internal::is_modint_t<mint>* = nullptr> constexpr istream& operator>>(istream& is, mint& x) noexcept {long long v = 0; std::cin >> v; x = v; return is;}
template <class mint, internal::is_modint_t<mint>* = nullptr> constexpr ostream& operator<<(ostream& os, const mint& x) noexcept {os << x.val(); return os;}
inline void _n() { std::cout << std::endl; }
template <class T> inline void _(const T a) { std::cout << a; }
template <class T> inline void _l(const T a) { _(a); _n(); }
template <class T> inline void _s(const T a) { _(a); _(' '); }
template <class T> inline void _v(const std::vector<T> v) { for(auto a : v) _(a); }
template <class T> inline void _vl(const std::vector<T> v) { for(auto a : v) _l(a); }
template <class T> inline void _vs(const std::vector<T> v) { for(auto a : v) _s(a); _n(); }
template <class T> inline void _vvl(const std::vector<std::vector<T>> v) { for(auto a : v) { _v(a); _n(); } }
template <class T> inline void _vvs(const std::vector<std::vector<T>> v) { for(auto a : v) { _vs(a); } }
inline void ynl(const bool b) {_l(b ? "yes" : "no");}
inline void yns(const bool b) {_l(b ? "Yes" : "No");}
inline void ynu(const bool b) {_l(b ? "YES" : "NO");}

constexpr int INF = numeric_limits<int>::max() >> 1;
constexpr long long INF_LL = numeric_limits<long long>::max() >> 1LL;
const long long MOD1 = 1000000007;
const long long MOD9 = 998244353;
using mint1 = atcoder::modint1000000007;
using mint9 = atcoder::modint998244353;

//* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *//

struct S {mint9 val; int size;};
S op (S a, S b) {return {a.val + b.val, a.size + b.size};}
S e () {return {0, 0};}

struct F {int n; bool b;};
S mapping (F f, S x) {if(f.b != 1) x.val = f.n * x.size; return x;}
F composition (F f, F g) {if(f.b == 1) return g; return f;}
F id () {return {0, 1};}


void solve() {
    
    
    int N; cin >> N;
    atcoder::lazy_segtree<S, op, e, F, mapping, composition, id> seg1(N);
    atcoder::lazy_segtree<S, op, e, F, mapping, composition, id> seg2(N);
    atcoder::lazy_segtree<S, op, e, F, mapping, composition, id> seg3(N);
    atcoder::lazy_segtree<S, op, e, F, mapping, composition, id> seg4(N);
    rep(i, N) {
        mint9 A; cin >> A;
        mint9 tmp = 1;
        tmp *= A; seg1.set(i, {tmp, 1});
        tmp *= A; seg2.set(i, {tmp, 1});
        tmp *= A; seg3.set(i, {tmp, 1});
        tmp *= A; seg4.set(i, {tmp, 1});
    }
    
    int Q; cin >> Q;
    while(Q--) {
        int t; cin >> t;
        
        if(t == 0) {
            int u, v, w, b; cin >> u >> v >> w >> b;
            u--; v--; w--;
            if(u > v) swap(u, v);
            
            if(u < w && w < v) {
                mint9 tmp = 1;
                tmp *= b; seg1.apply(u, v+1, {(int)tmp.val(), 0});
                tmp *= b; seg2.apply(u, v+1, {(int)tmp.val(), 0});
                tmp *= b; seg3.apply(u, v+1, {(int)tmp.val(), 0});
                tmp *= b; seg4.apply(u, v+1, {(int)tmp.val(), 0});
            } else {
                mint9 tmp = 1;
                tmp *= b; seg1.apply(0, u+1, {(int)tmp.val(), 0}); seg1.apply(v, N, {(int)tmp.val(), 0});
                tmp *= b; seg2.apply(0, u+1, {(int)tmp.val(), 0}); seg2.apply(v, N, {(int)tmp.val(), 0});
                tmp *= b; seg3.apply(0, u+1, {(int)tmp.val(), 0}); seg3.apply(v, N, {(int)tmp.val(), 0});
                tmp *= b; seg4.apply(0, u+1, {(int)tmp.val(), 0}); seg4.apply(v, N, {(int)tmp.val(), 0});
            }

            
        } else {
            
            int u, v, w; cin >> u >> v >> w;
            u--; v--; w--;
            if(u > v) swap(u, v);
            
            mint9 L = (u < w && w < v) ? v - u + 1 : N - v + u + 1;
            mint9 M = (u < w && w < v) ? seg1.prod(u, v+1).val : seg1.prod(0, u+1).val + seg1.prod(v, N).val;
            mint9 X1 = M;
            mint9 X2 = (u < w && w < v) ? seg2.prod(u, v+1).val : seg2.prod(0, u+1).val + seg2.prod(v, N).val;
            mint9 X3 = (u < w && w < v) ? seg3.prod(u, v+1).val : seg3.prod(0, u+1).val + seg3.prod(v, N).val;
            mint9 X4 = (u < w && w < v) ? seg4.prod(u, v+1).val : seg4.prod(0, u+1).val + seg4.prod(v, N).val;
            M /= L;
            
            mint9 ans = 0;
            if(t == 2) {
                ans += 1 * X2;
                ans -= 2 * X1 * M;
                ans += 1 * M * M * L;
            } else if(t == 3) {
                ans += 1 * X3;
                ans -= 3 * X2 * M;
                ans += 3 * X1 * M * M;
                ans -= 1 * M * M * M * L;
            } else if(t == 4) {
                ans += 1 * X4;
                ans -= 4 * X3 * M;
                ans += 6 * X2 * M * M;
                ans -= 4 * X1 * M * M * M;
                ans += 1 * M * M * M * M * L;
            }
            ans /= L;
            
            _l(ans);
            
        }
    }
    
    
    
    
}

//* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *//

int main() {
    
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    
    solve();
    
    return 0;
}
0