-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsnippet.cpp
More file actions
127 lines (109 loc) · 2.94 KB
/
snippet.cpp
File metadata and controls
127 lines (109 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using lll = __int128;
using ull = unsigned long long;
using uint = unsigned int;
using ushort = unsigned short;
template<typename T> using vec2D = vector<vector<T>>;
template<typename T, typename U> using pr = pair<T, U>;
template<typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using max_heap = priority_queue<T, vector<T>, less<T>>;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fromv(v, n) v.begin() + n, v.end()
#define tov(v, n) v.begin(), v.begin() + n
#define atv(v, n) v.begin() + n
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mp make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define len(x) (int)(x).length()
#define lb lower_bound
#define ub upper_bound
#define endl '\n'
#define feach(var, container) for (auto &var : container)
#define debug(x) cerr << #x << " = " << (x) << endl;
const int INF = 1e9;
const ll INF2 = 1e18;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = 1e-9;
typedef struct Fenwick {
vector<ll> bit;
int n;
Fenwick(int n) {
this->n = n;
bit.assign(n, 0);
}
void add(int i, ll val, int mod = MOD) {
for (; i < n; i += i & -i) {
bit[i] += val;
if (bit[i] >= MOD) bit[i] -= MOD;
if (bit[i] < 0) bit[i] += MOD;
}
}
ll sum(int i) const {
ll r = 0;
for (; i > 0; i -= i & -i) {
r += bit[i];
if (r >= MOD) r -= MOD;
}
return r;
}
ll sum(int l, int r, ll mod = MOD) {
return ((sum(r) - sum(l - 1)) % mod + mod) % mod;
}
};
void solve() {
auto modpow = [](ll base, ll exp, ll mod = MOD) {
ll result = 1;
base %= mod;
while (exp > 0) {
if (exp & 1) result = (result * base) % mod;
base = (base * base) % mod;
exp >>= 1;
}
return result;
};
int q; cin >> q;
const ll MAX = 100000;
Fenwick fw(MAX);
ll inv = (MOD + 1) / 2;
vector<ll> invp(MAX + 1, 1);
for (int i = 1; i <= MAX; i++) {
invp[i] = invp[i - 1] * inv % MOD;
}
while (q--) {
int c; cin >> c;
if (c == 1) {
ll x; cin >> x;
ll idx = min(x, MAX);
ll pref = fw.sum(idx);
ll ans = modpow(2, x) * pref % MOD;
cout << ans << endl;
} else {
int x; cin >> x;
ll b = 0;
for (int i = 0; i < x; i++) {
ll x; cin >> x;
b += x % MOD;
if (b >= MOD) b -= MOD;
}
fw.add(x, b * invp[x] % MOD);
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin>>t;
while (t--) solve();
return 0;
}