結果

問題 No.1067 #いろいろな色 / Red and Blue and more various colors (Middle)
ユーザー wunderkammer2wunderkammer2
提出日時 2021-04-23 16:53:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 343 ms / 2,000 ms
コード長 6,845 bytes
コンパイル時間 1,543 ms
コンパイル使用メモリ 142,328 KB
実行使用メモリ 287,084 KB
最終ジャッジ日時 2023-09-17 11:12:37
合計ジャッジ時間 5,314 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,692 KB
testcase_01 AC 3 ms
5,816 KB
testcase_02 AC 4 ms
5,704 KB
testcase_03 AC 3 ms
5,712 KB
testcase_04 AC 4 ms
5,800 KB
testcase_05 AC 4 ms
5,888 KB
testcase_06 AC 4 ms
5,720 KB
testcase_07 AC 4 ms
5,804 KB
testcase_08 AC 3 ms
5,816 KB
testcase_09 AC 4 ms
5,708 KB
testcase_10 AC 4 ms
5,692 KB
testcase_11 AC 220 ms
181,960 KB
testcase_12 AC 143 ms
110,960 KB
testcase_13 AC 323 ms
253,508 KB
testcase_14 AC 167 ms
141,648 KB
testcase_15 AC 70 ms
57,356 KB
testcase_16 AC 62 ms
45,540 KB
testcase_17 AC 14 ms
13,048 KB
testcase_18 AC 180 ms
147,772 KB
testcase_19 AC 184 ms
156,400 KB
testcase_20 AC 86 ms
61,592 KB
testcase_21 AC 343 ms
287,084 KB
testcase_22 AC 342 ms
287,044 KB
testcase_23 AC 341 ms
287,012 KB
testcase_24 AC 3 ms
5,692 KB
testcase_25 AC 4 ms
5,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<fstream>       //ファイルストリーム(標準入力変更用)
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

//名前
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef map<string, int> msi;
typedef map<string, ll> msll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pllll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;

//定数
const ll MOD = 998244353;
const ll INF = 1000000000000000000;
const int MAXR = 100000;             //10^5:配列の最大のrange

//マクロ
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,s,e) for(int i=s;i<e;i++)
#define repse(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define in1(x1) cin >> x1
#define in2(x1, x2) cin >> x1 >> x2
#define in3(x1, x2, x3) cin >> x1 >> x2 >> x3
#define in4(x1, x2, x3, x4) cin >> x1 >> x2 >> x3 >> x4
#define in5(x1, x2, x3, x4, x5) cin >> x1 >> x2 >> x3 >> x4 >> x5
#define in6(x1, x2, x3, x4, x5, x6) cin >> x1 >> x2 >> x3 >> x4 >> x5 >> x6
#define inN(x, N) rep(i, N) in1(x[i])
#define outl(x) cout << x << endl
#define out2l(x, y) cout << x << " " << y << endl 

//よく使う関数
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
inline ll div_ceil(ll a, ll b) { return (a + (b - 1)) / b; }


template<ll mod> class modint {
public:
    ll val = 0;
    //コンストラクタ
    modint(ll x = 0) { while (x < 0)x += mod; val = x % mod; }
    //コピーコンストラクタ
    modint(const modint& r) { val = r.val; }
    //算術演算子
    modint operator -() { return modint(-val); } //単項
    modint operator +(const modint& r) { return modint(*this) += r; }
    modint operator -(const modint& r) { return modint(*this) -= r; }
    modint operator *(const modint& r) { return modint(*this) *= r; }
    modint operator /(const modint& r) { return modint(*this) /= r; }
    //代入演算子
    modint& operator +=(const modint& r) {
        val += r.val;
        if (val >= mod)val -= mod;
        return *this;
    }
    modint& operator -=(const modint& r) {
        if (val < r.val)val += mod;
        val -= r.val;
        return *this;
    }
    modint& operator *=(const modint& r) {
        val = val * r.val % mod;
        return *this;
    }
    modint& operator /=(const modint& r) {
        ll a = r.val, b = mod, u = 1, v = 0;
        while (b) {
            ll t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % mod;
        if (val < 0)val += mod;
        return *this;
    }
    //等価比較演算子
    bool operator ==(const modint& r) { return this->val == r.val; }
    bool operator <(const modint& r) { return this->val < r.val; }
    bool operator !=(const modint& r) { return this->val != r.val; }
};

using mint = modint<MOD>;

//入出力ストリーム
istream& operator >>(istream& is, mint& x)
{//xにconst付けない
    ll t; is >> t;
    x = t;
    return (is);
}
ostream& operator <<(ostream& os, const mint& x)
{
    return os << x.val;
}

//累乗
mint modpow(const mint& a, ll n)
{
    if (n == 0)return 1;
    mint t = modpow(a, n / 2);
    t = t * t;
    if (n & 1)t = t * a;
    return t;
}

//二項係数の計算
mint fac[MAXR + 1], finv[MAXR + 1], inv[MAXR + 1];

//テーブルの作成
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    repse(i, 2, MAXR)
    {
        fac[i] = fac[i - 1] * mint(i);
        inv[i] = -inv[MOD % i] * mint(MOD / i);
        finv[i] = finv[i - 1] * inv[i];
    }
}

//演算部分
mint COM(ll n, ll k) {
    if (n < k)return 0;
    if (n < 0 || k < 0)return 0;
    return fac[n] * finv[k] * finv[n - k];
}


template <typename T>
vector<T> compress(vector<T> &X) {
    // ソートした結果を vals に
    vector<T> vals = X;
    //sort(vals.begin(), vals.end(), greater<T>());
    // 隣り合う重複を削除(unique), 末端のゴミを削除(erase)
    vals.erase(unique(vals.begin(), vals.end()), vals.end());
    // 各要素ごとに二分探索で位置を求める
    for (int i = 0; i < (int)X.size(); i++) {
        X[i] = lower_bound(vals.begin(), vals.end(), X[i]) - vals.begin();
    }
    return vals;
}

map<int, int> compress2(vi &X)
{
    sort(X.begin(), X.end());

    reverse(all(X));

    map<int, int> m;
    
    rep(i, X.size()) m[X[i]] = i;

    return m;
}
 

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    //標準入力をファイルに変更
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());

    int N, Q;
    in2(N, Q);

    vi A(N);
    inN(A, N);

    vi L(Q), R(Q), P(Q);
    rep(i, Q) in3(L[i], R[i], P[i]);

    vi B = A;
    auto v = compress2(B);

    vector<vector<mint>> dp(N + 1, vector<mint>(N + 1, 0)); 
    dp[0][0] = 1;

    rep(i, B.size()) 
    {
        mint a = B[i];

        repse(j, 0, N)
        {
            //選ばない場合
            dp[i + 1][j] += dp[i][j] * (a - 1);

            //選ぶ場合
            if(j < N) dp[i + 1][j + 1] += dp[i][j];
        }
    }

    sort(all(A));

    vector<mint> cum(N);
    cum[0] = 1;
    rep(i, N - 1) cum[i + 1] = cum[i] * A[i];
    reverse(all(cum));

    rep(q, Q)
    {
        int l = L[q];
        int r = R[q];
        int p = P[q];

        ll ans = 0;

        repse(i, l, r)
        {
            auto x = v.lower_bound(i)->second;
            //ans ^= c[x->second][p].val % MOD;
            ans ^= (dp[x + 1][p] * cum[x]).val;
        }

        outl(ans % MOD);
    }

    return 0;
}
0