結果
問題 | No.2170 Left Addition Machine |
ユーザー | 👑 Nachia |
提出日時 | 2022-12-22 00:15:01 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 93 ms / 2,000 ms |
コード長 | 3,857 bytes |
コンパイル時間 | 873 ms |
コンパイル使用メモリ | 86,512 KB |
実行使用メモリ | 6,400 KB |
最終ジャッジ日時 | 2024-04-29 05:20:23 |
合計ジャッジ時間 | 14,182 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 80 ms
6,144 KB |
testcase_04 | AC | 29 ms
5,376 KB |
testcase_05 | AC | 48 ms
5,376 KB |
testcase_06 | AC | 50 ms
5,376 KB |
testcase_07 | AC | 70 ms
5,376 KB |
testcase_08 | AC | 16 ms
5,376 KB |
testcase_09 | AC | 54 ms
5,376 KB |
testcase_10 | AC | 10 ms
5,376 KB |
testcase_11 | AC | 38 ms
5,376 KB |
testcase_12 | AC | 88 ms
6,400 KB |
testcase_13 | AC | 87 ms
6,400 KB |
testcase_14 | AC | 86 ms
6,400 KB |
testcase_15 | AC | 86 ms
6,272 KB |
testcase_16 | AC | 88 ms
6,272 KB |
testcase_17 | AC | 86 ms
6,400 KB |
testcase_18 | AC | 85 ms
6,272 KB |
testcase_19 | AC | 87 ms
6,272 KB |
testcase_20 | AC | 87 ms
6,400 KB |
testcase_21 | AC | 45 ms
5,376 KB |
testcase_22 | AC | 44 ms
5,376 KB |
testcase_23 | AC | 44 ms
5,376 KB |
testcase_24 | AC | 44 ms
5,376 KB |
testcase_25 | AC | 46 ms
5,376 KB |
testcase_26 | AC | 45 ms
5,376 KB |
testcase_27 | AC | 45 ms
5,376 KB |
testcase_28 | AC | 45 ms
5,376 KB |
testcase_29 | AC | 44 ms
5,376 KB |
testcase_30 | AC | 89 ms
6,272 KB |
testcase_31 | AC | 89 ms
6,400 KB |
testcase_32 | AC | 87 ms
6,272 KB |
testcase_33 | AC | 87 ms
6,400 KB |
testcase_34 | AC | 89 ms
6,400 KB |
testcase_35 | AC | 88 ms
6,272 KB |
testcase_36 | AC | 87 ms
6,272 KB |
testcase_37 | AC | 88 ms
6,400 KB |
testcase_38 | AC | 87 ms
6,272 KB |
testcase_39 | AC | 45 ms
5,376 KB |
testcase_40 | AC | 45 ms
5,376 KB |
testcase_41 | AC | 45 ms
5,376 KB |
testcase_42 | AC | 48 ms
5,376 KB |
testcase_43 | AC | 45 ms
5,376 KB |
testcase_44 | AC | 45 ms
5,376 KB |
testcase_45 | AC | 44 ms
5,376 KB |
testcase_46 | AC | 44 ms
5,376 KB |
testcase_47 | AC | 45 ms
5,376 KB |
testcase_48 | AC | 93 ms
6,272 KB |
testcase_49 | AC | 89 ms
6,272 KB |
testcase_50 | AC | 91 ms
6,272 KB |
testcase_51 | AC | 90 ms
6,272 KB |
testcase_52 | AC | 89 ms
6,272 KB |
testcase_53 | AC | 88 ms
6,272 KB |
testcase_54 | AC | 89 ms
6,272 KB |
testcase_55 | AC | 86 ms
6,272 KB |
testcase_56 | AC | 89 ms
6,272 KB |
testcase_57 | AC | 85 ms
6,400 KB |
testcase_58 | AC | 84 ms
6,400 KB |
testcase_59 | AC | 86 ms
6,400 KB |
testcase_60 | AC | 85 ms
6,272 KB |
testcase_61 | AC | 85 ms
6,272 KB |
testcase_62 | AC | 87 ms
6,272 KB |
testcase_63 | AC | 87 ms
6,400 KB |
testcase_64 | AC | 86 ms
6,400 KB |
testcase_65 | AC | 85 ms
6,400 KB |
testcase_66 | AC | 16 ms
5,376 KB |
testcase_67 | AC | 72 ms
6,272 KB |
testcase_68 | AC | 88 ms
6,400 KB |
ソースコード
#line 1 "Main.cpp" #include <iostream> #include <string> #include <vector> #include <algorithm> #include <utility> #include <atcoder/modint> #line 2 "nachia\\set\\word-size-tree.hpp" #line 5 "nachia\\set\\word-size-tree.hpp" namespace nachia{ struct WordsizeTree{ using Word = unsigned long long; static constexpr unsigned int W = 64; int N; std::vector<std::vector<Word>> A; static int highBit(Word x){ if(x == 0) return 0; return W-1 - __builtin_clzll(x); } static int lowBit(Word x){ if(x == 0) return W; return __builtin_ctzll(x); } WordsizeTree(unsigned int length){ N = length; int n = length; do { std::vector<Word> a(n/W+1,0); A.emplace_back(std::move(a)); n /= W; } while(n); } WordsizeTree(const std::string& binStr = ""){ N = binStr.size(); int n = N; { std::vector<Word> a(n/W+1); for(int i=0; i<n; i++) if(binStr[i] == '1'){ a[i/W] |= (Word)1 << (i%W); } A.emplace_back(std::move(a)); n /= W; } while(n){ std::vector<Word> a(n/W+1,0); for(int i=0; i<=n; i++){ if(A.back()[i]) a[i/W] |= (Word)1 << (i%W); } A.emplace_back(std::move(a)); n /= W; } } void insert(int x){ for(auto& a : A){ a[x/W] |= (Word)1 << (x % W); x /= W; } } void erase(int x){ for(auto& a : A){ a[x/W] &= ~((Word)1 << (x % W)); if(a[x/W]) return; x /= W; } } int count(int x) const { return (int)((A[0][x/W] >> (x%W)) & 1); } int noLessThan(int x) const { int d = 0, i = x; while(true){ if(d >= (int)A.size()) return -1; if(i/W >= (int)A[d].size()) return -1; Word m = A[d][i/W] & ((~(Word)0) << (i%W)); if(!m){ d++; i /= W; i++; } else{ int to = lowBit(m); i = i/W*W + to; if(d == 0) break; i *= W; d--; } } return i; } int noGreaterThan(int x) const { int d = 0, i = x; while(true){ if(i < 0) return -1; if(d >= (int)A.size()) return -1; Word m = A[d][i/W] & ~((~(Word)1) << (i%W)); if(!m){ d++; i /= W; i--; } else{ int to = highBit(m); i = i/W*W + to; if(d == 0) break; i *= W; i += W-1; d--; } } return i; } }; } // namespace nachia #line 8 "Main.cpp" using namespace std; using i32 = int32_t; using u32 = uint32_t; using i64 = int64_t; using u64 = uint64_t; #define rep(i,n) for(int i=0; i<(int)(n); i++) const i64 INF = 1001001001001001001; using Modint = atcoder::static_modint<998244353>; int main(){ int N, Q; cin >> N >> Q; vector<int> A(N); rep(i,N) cin >> A[i]; vector<Modint> B(N); rep(i,N) B[i] = Modint::raw(A[i]); vector<Modint> sumB(N+1); for(int i=N-1; i>=0; i--) sumB[i] = sumB[i+1] + sumB[i+1] + B[i]; vector<Modint> pow2(N+1); pow2[0] = 1; for(int i=1; i<=N; i++) pow2[i] = pow2[i-1] + pow2[i-1]; nachia::WordsizeTree S(N); rep(i,N-1) if(A[i] >= A[i+1]) S.insert(i); rep(i,Q){ int l, r; cin >> l >> r; l--; l = max(l, S.noGreaterThan(r-2) + 1); Modint ans = sumB[l+1] - sumB[r] * pow2[r-l-1] + B[l]; cout << ans.val() << '\n'; } return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } } ios_do_not_sync_instance;