結果

問題 No.1067 #いろいろな色 / Red and Blue and more various colors (Middle)
ユーザー tonegawatonegawa
提出日時 2020-08-12 08:23:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 467 ms / 2,000 ms
コード長 1,782 bytes
コンパイル時間 1,651 ms
コンパイル使用メモリ 131,540 KB
実行使用メモリ 285,056 KB
最終ジャッジ日時 2024-04-18 00:13:27
合計ジャッジ時間 5,526 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 301 ms
180,352 KB
testcase_12 AC 176 ms
109,440 KB
testcase_13 AC 430 ms
251,900 KB
testcase_14 AC 228 ms
140,160 KB
testcase_15 AC 84 ms
55,808 KB
testcase_16 AC 72 ms
43,648 KB
testcase_17 AC 14 ms
11,136 KB
testcase_18 AC 235 ms
146,048 KB
testcase_19 AC 251 ms
154,880 KB
testcase_20 AC 96 ms
60,032 KB
testcase_21 AC 449 ms
285,056 KB
testcase_22 AC 461 ms
284,928 KB
testcase_23 AC 467 ms
284,928 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d>>(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;


int main(int argc, char const *argv[]) {
  ll P = 998244353;
  ll n, q;scanf("%lld %lld", &n,&q);
  vll a(n);re(i, n) scanf("%lld", &a[i]);
  sort(all(a));
  reverse(all(a));
  vvl dp = VV(n+1, n+1, 0, ll);//i de j ball
  dp[0][0] = 1;
  for(int i=0;i<n;i++){
    for(int j=0;j<=n;j++){
      //使わない場合
      dp[i+1][j]=(dp[i+1][j]+(dp[i][j]*(a[i]-1)))%P;
      //使う場合
      dp[i+1][j+1]=(dp[i+1][j+1]+dp[i][j])%P;
    }
  }

  for(int i=0;i<=n;i++){
    ll mul = 1;
    for(int j=i+1;j<=n;j++) mul = (mul * a[j-1])%P;
    for(int j=0;j<=n;j++) dp[i][j] = (dp[i][j] * mul)%P;
  }
  reverse(all(a));
  map<ll, ll> mp;
  for(int i=0;i<n;i++){
    auto itr = mp.find(a[i]);
    if(itr==mp.end()) mp.emplace(a[i], 1);
    else (*itr).second++;
  }

  for(int i=0;i<q;i++){
    ll l, r, p;scanf("%lld %lld %lld", &l,&r,&p);
    ll lb = lower_bound(all(a), l) - a.begin();//l未満いくつ
    auto itr = mp.lower_bound(l);
    ll ret = 0;
    for(int j=l;j<=r;j++){
      ll up = n - lb;
      ret ^= dp[up][p];
      if(itr!=mp.end()&&(*itr).first==j) {
        lb += (*itr).second;
        itr++;
      }
    }
    printf("%lld\n", ret);
  }
  // O(N^2 + Nlog(N) + Q(logN + 200))
  return 0;
}
0