結果

問題 No.1067 #いろいろな色 / Red and Blue and more various colors (Middle)
ユーザー どららどらら
提出日時 2020-05-29 23:07:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 422 ms / 2,000 ms
コード長 3,089 bytes
コンパイル時間 1,736 ms
コンパイル使用メモリ 171,936 KB
実行使用メモリ 288,308 KB
最終ジャッジ日時 2024-04-24 00:55:54
合計ジャッジ時間 9,867 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 211 ms
288,268 KB
testcase_01 AC 209 ms
288,192 KB
testcase_02 AC 210 ms
288,108 KB
testcase_03 AC 210 ms
288,128 KB
testcase_04 AC 211 ms
288,112 KB
testcase_05 AC 210 ms
288,164 KB
testcase_06 AC 210 ms
288,172 KB
testcase_07 AC 208 ms
288,132 KB
testcase_08 AC 209 ms
288,216 KB
testcase_09 AC 208 ms
288,180 KB
testcase_10 AC 209 ms
288,148 KB
testcase_11 AC 319 ms
288,308 KB
testcase_12 AC 296 ms
288,088 KB
testcase_13 AC 343 ms
288,272 KB
testcase_14 AC 294 ms
288,300 KB
testcase_15 AC 244 ms
288,128 KB
testcase_16 AC 251 ms
288,104 KB
testcase_17 AC 218 ms
288,260 KB
testcase_18 AC 297 ms
288,160 KB
testcase_19 AC 291 ms
288,220 KB
testcase_20 AC 271 ms
288,100 KB
testcase_21 AC 422 ms
288,196 KB
testcase_22 AC 417 ms
288,212 KB
testcase_23 AC 417 ms
288,280 KB
testcase_24 AC 210 ms
288,180 KB
testcase_25 AC 210 ms
288,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

static const long long mod = 998244353;
struct mint {
  long long x;
  mint(ll x = 0):x(x%mod) {}
  mint& operator+=(const mint a) {
    (x += a.x) %= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    (x += mod-a.x) %= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint ret(*this);
    return ret += a;
  }
  mint operator-(const mint a) const {
    mint ret(*this);
    return ret -= a;
  }
  mint operator*(const mint a) const {
    mint ret(*this);
    return ret *= a;
  }
  mint pow(ll t) const {
    if(t==0) return mint(1);
    mint a = pow(t>>1);
    a *= a;
    if(t&1) a *= *this;
    return a;
  }
  
  //for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint ret(*this);
    return ret /= a;
  }
};
ostream &operator<<(ostream& os, const mint& x) {
  os << x.x;
  return os;
}
class modutils {
  vector<mint> fact, invfact;
public:
  modutils(int n = 200005):fact(n+1),invfact(n+1) {
    fact[0] = 1;
    for(int i=1; i<=n; i++) fact[i] = fact[i-1] * i;
    invfact[n] = fact[n].inv();
    for(int i=n; i>=1; i--) invfact[i-1] = invfact[i] * i;
  }
  mint pow(mint x, ll n) {
    return x.pow(n);
  }
  mint comb(ll n, ll k) {
    if(n<0 || k<0 || n<k) return 0;
    return fact[n] * invfact[k] * invfact[n-k];
  }
  mint perm(ll n, ll k) {
    if(n<0 || k<0 || n<k) return 0;
    return fact[n] * invfact[n-k];
  }
  mint fac(ll n) {
    return fact[n];
  }
};
modutils mutil;


mint dp[6005][6005];
mint rem[6005];

int main(){
  int N, Q;
  cin >> N >> Q;
  vector<int> v;
  rep(i,N){
    int a;
    cin >> a;
    v.push_back(a);
  }
  sort(ALLOF(v));
  reverse(ALLOF(v));

  dp[0][0] = 1;
  
  rep(i,N){
    rep(j,N+1){
      dp[i+1][j] += dp[i][j]*(v[i]-1);
      dp[i+1][j+1] += dp[i][j];
    }
  }

  rem[N] = 1;
  for(int i=N-1; i>=0; i--){
    rem[i] = rem[i+1] * v[i];
  }
  
  rep(i,Q){
    int l, r, q;
    cin >> l >> r >> q;

    ll ret = 0;
    REP(x,l,r+1){
      int lb = 0, ub = N;
      while(ub-lb>1){
        int mid = (lb+ub)/2;

        if(x<=v[mid]) lb = mid;
        else ub = mid;
      }

      //cout << lb << " " << dp[lb+1][q] << " " << rem[lb+1] << endl;
      
      mint tmp = dp[lb+1][q] * rem[lb+1];
      ret ^= tmp.x;
      ret %= mod;
    }

    cout << ret << endl;
  }
  
  
  return 0;
}

0