結果

問題 No.2170 Left Addition Machine
ユーザー CleyLCleyL
提出日時 2024-02-12 12:51:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 606 ms / 2,000 ms
コード長 4,306 bytes
コンパイル時間 1,273 ms
コンパイル使用メモリ 133,124 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-12 12:51:55
合計ジャッジ時間 42,694 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 544 ms
6,676 KB
testcase_04 AC 252 ms
6,676 KB
testcase_05 AC 346 ms
6,676 KB
testcase_06 AC 351 ms
6,676 KB
testcase_07 AC 499 ms
6,676 KB
testcase_08 AC 58 ms
6,676 KB
testcase_09 AC 468 ms
6,676 KB
testcase_10 AC 68 ms
6,676 KB
testcase_11 AC 246 ms
6,676 KB
testcase_12 AC 580 ms
6,676 KB
testcase_13 AC 600 ms
6,676 KB
testcase_14 AC 583 ms
6,676 KB
testcase_15 AC 604 ms
6,676 KB
testcase_16 AC 579 ms
6,676 KB
testcase_17 AC 604 ms
6,676 KB
testcase_18 AC 579 ms
6,676 KB
testcase_19 AC 601 ms
6,676 KB
testcase_20 AC 578 ms
6,676 KB
testcase_21 AC 443 ms
6,676 KB
testcase_22 AC 417 ms
6,676 KB
testcase_23 AC 421 ms
6,676 KB
testcase_24 AC 442 ms
6,676 KB
testcase_25 AC 418 ms
6,676 KB
testcase_26 AC 418 ms
6,676 KB
testcase_27 AC 444 ms
6,676 KB
testcase_28 AC 419 ms
6,676 KB
testcase_29 AC 447 ms
6,676 KB
testcase_30 AC 550 ms
6,676 KB
testcase_31 AC 563 ms
6,676 KB
testcase_32 AC 556 ms
6,676 KB
testcase_33 AC 553 ms
6,676 KB
testcase_34 AC 553 ms
6,676 KB
testcase_35 AC 548 ms
6,676 KB
testcase_36 AC 554 ms
6,676 KB
testcase_37 AC 555 ms
6,676 KB
testcase_38 AC 573 ms
6,676 KB
testcase_39 AC 406 ms
6,676 KB
testcase_40 AC 407 ms
6,676 KB
testcase_41 AC 427 ms
6,676 KB
testcase_42 AC 411 ms
6,676 KB
testcase_43 AC 431 ms
6,676 KB
testcase_44 AC 404 ms
6,676 KB
testcase_45 AC 407 ms
6,676 KB
testcase_46 AC 416 ms
6,676 KB
testcase_47 AC 406 ms
6,676 KB
testcase_48 AC 544 ms
6,676 KB
testcase_49 AC 547 ms
6,676 KB
testcase_50 AC 550 ms
6,676 KB
testcase_51 AC 575 ms
6,676 KB
testcase_52 AC 544 ms
6,676 KB
testcase_53 AC 539 ms
6,676 KB
testcase_54 AC 541 ms
6,676 KB
testcase_55 AC 553 ms
6,676 KB
testcase_56 AC 549 ms
6,676 KB
testcase_57 AC 591 ms
6,676 KB
testcase_58 AC 580 ms
6,676 KB
testcase_59 AC 605 ms
6,676 KB
testcase_60 AC 578 ms
6,676 KB
testcase_61 AC 606 ms
6,676 KB
testcase_62 AC 577 ms
6,676 KB
testcase_63 AC 588 ms
6,676 KB
testcase_64 AC 579 ms
6,676 KB
testcase_65 AC 591 ms
6,676 KB
testcase_66 AC 132 ms
6,676 KB
testcase_67 AC 527 ms
6,676 KB
testcase_68 AC 586 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 2 "/home/sakflat/CP/_library/cpp/template/template.cpp"

//yukicoder@cpp17

#include <iostream>
#include <iomanip>

#include <algorithm>

#include <cmath>
#include <cctype>
#include <climits>
#include <cassert>

#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>

#include <random>

#include <bitset>

#include <complex>

#include <utility>

#include <numeric>

#include <functional>


using namespace std;
using ll = long long;
using P = pair<ll,ll>;


const ll MOD = 998244353;
const ll MODx = 1000000007;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62LL)-1;
const double EPS = (1e-10);


P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};


template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }
 
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる

計算量は変わらないが楽できるシリーズ
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる
*/

/* comment outed because can cause bugs
__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}
*/
#line 2 "/home/sakflat/CP/_library/cpp/template/basic.cpp"

#line 2 "/home/sakflat/CP/_library/cpp/data-structure/mod-int/mod-int.cpp"

template <int mod>
struct ModInt{
  int n;
  ModInt():n(0){}
  ModInt(long long n_):n(n_ >= 0 ? n_%mod : mod - ((-n_)%mod) ){}
  ModInt(int n_):n(n_ >= 0 ? n_%mod : mod - ((-n_)%mod) ){}

  ModInt &operator+=(const ModInt &p){
    if((n+=p.n) >= mod)n-=mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p){
    n+=mod-p.n;
    if(n >= mod)n-=mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p){
    n = (int) ((1LL*n*p.n)%mod);
    return *this;
  }
  ModInt &operator/=(const ModInt &p){
    *this *= p.inverse();
    return *this;
  }
  ModInt operator-() const {return ModInt(-n);}
  ModInt operator+(const ModInt &p) const {return ModInt(*this) += p;}
  ModInt operator-(const ModInt &p) const {return ModInt(*this) -= p;}
  ModInt operator*(const ModInt &p) const {return ModInt(*this) *= p;}
  ModInt operator/(const ModInt &p) const {return ModInt(*this) /= p;}

  bool operator==(const ModInt &p) const {return n==p.n;}
  bool operator<(const ModInt &p) const {return n<p.n;}
  bool operator>(const ModInt &p) const {return n>p.n;}
  bool operator>=(const ModInt &p) const {return n>=p.n;}
  bool operator<=(const ModInt &p) const {return n<=p.n;}
  bool operator!=(const ModInt &p) const {return n!=p.n;}

  ModInt inverse() const {
    int a = n,b = mod,u = 1,v = 0;
    while(b){
      int t = a/b;
      a -= t*b; swap(a,b);
      u -= t*v; swap(u,v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t z) const {
    ModInt ret(1),mul(n);
    while(z > 0){
      if(z & 1) ret *= mul;
      mul *= mul;
      z >>= 1;
    }
    return ret;
  }

  int getMod() const {
    return mod;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p){
    return os << p.n;
  }
  friend istream &operator>>(istream &is, ModInt &a){
    int64_t t;
    is >> t;
    a = ModInt<mod> ((long long)t);
    return (is);

  }
};
using mint = ModInt<MOD>;


template <typename T>
T uPow(T z,T n, T mod){
  T ans = 1;
  while(n != 0){
    if(n%2){
      ans*=z;
      if(mod)ans%=mod;
    }
    n >>= 1;
    z*=z;
    if(mod)z%=mod;
  }
  return ans;
}


int main(){
  int n,q;cin>>n>>q;
  vector<int> A(n);
  vector<mint> R(n+1, 0);
  for(int i = 0; n > i; i++){
    cin>>A[i];
  }
  mint kei = 1;
  for(int i = 1; n >= i; i++){
    R[i] = R[i-1] + (mint)A[i-1]*kei;
    kei *= 2;
  }
  vector<int> si;
  si.push_back(0);
  for(int i = 1; n > i; i++){
    if(A[i-1] >= A[i]){
      si.push_back(i);
    }
  }
  si.push_back(n);
  for(int i = 0; q > i; i++){
    int l,r;cin>>l>>r;l--;r--;
    auto z = lower_bound(si.begin(), si.end(), r+1);z--;
    l = max(l, *z);
    cout << (mint)A[l] + (R[r+1]-R[l+1])/(mint)uPow(2LL, (long long)(l+1), MOD) << endl;
  }
  return 0;
}
0