// compile: make data
// run: ./data < data.in
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#ifdef LOCAL
#include <debug/codeforces.h>
#define debug(x...) _debug_print(#x, x);
#define Debug(x...) _debug_print_format(#x, x);
std::ifstream terminal("/dev/tty");
#define PP cerr<<"\033[1;30mpause...\e[0m",terminal.ignore();
#else
#define debug(x...)
#define Debug(x...)
#define PP
#endif
template<typename...Args> void print_(Args...args){((cout<<args<<" "),...)<<endl;}
#define rep(i,a,b) for(int i=(a);i<(int)(b);++i)
#define sz(v) ((int)(v).size())
#define print(...) print_(__VA_ARGS__);
#define FIND(a, x) ((find(a.begin(),a.end(),(x))!=a.end())?1:0)
#define cmin(x,...) x=min({(x),__VA_ARGS__})
#define cmax(x,...) x=max({(x),__VA_ARGS__})
#define INTMAX (int)(9223372036854775807)
#define INF (int)(1152921504606846976)
#define NaN (int)(0x8b88e1d0595d51d1)
#define double long double
#define int long long
#define uint unsigned long long
#define MAXN 200010
#define P 1000000007
template <class T> struct segtree {
struct node {
int l, r;
T val;
node *ch[2];
};
int cnt = 0;
T DEFAULT_VALUE;
node *newnode(int l, int r) {
node *x = &datalist[cnt++];
x->l = l, x->r = r;
x->ch[0] = x->ch[1] = nullptr;
return x;
}
vector<int> a;
vector<node> datalist;
node *root;
segtree(vector<int> arr) {
a = arr, build();
}
void pushup(node *x) {
if (!x) return;
if (!x->ch[0] && !x->ch[1]) return;
if (x->ch[0]) pushdown(x->ch[0]);
if (x->ch[1]) pushdown(x->ch[1]);
if (x->ch[0] && x->ch[1]) x->val = x->ch[0]->val + x->ch[1]->val;
else x->val = x->ch[!x->ch[0]]->val;
}
void pushdown(node *x) {
if (!x) return;
if (x->ch[0]) x->val.pushdown(x->ch[0]->val, 0);
if (x->ch[1]) x->val.pushdown(x->ch[1]->val, 1);
x->val.clear();
}
T query(int ql, int qr) {
function<T(node*)> dfs = [&](node *x) -> T {
if (ql > x->r || qr < x->l) return DEFAULT_VALUE;
pushdown(x);
if (x->l >= ql && x->r <= qr) return x->val;
return dfs(x->ch[0]) + dfs(x->ch[1]);
};
return dfs(root);
}
template <typename U> void modify(int ql, int qr, U val) {
function<void(node*)> dfs = [&](node *x) -> void {
if (ql > x->r || qr < x->l) return;
pushdown(x);
if (x->l >= ql && x->r <= qr) {
x->val.update(val, ql, qr);
return;
}
dfs(x->ch[0]), dfs(x->ch[1]);
pushup(x);
};
dfs(root);
}
void build() {
datalist.resize(sz(a) * 2);
function<node*(int, int)> dfs = [&](int l, int r) {
node *x = newnode(l, r);
if (r > l) x->ch[0] = dfs(l, (l+r) >> 1), x->ch[1] = dfs(((l+r)>>1) + 1, r);
else x->val.set(l, a[l]);
pushup(x);
return x;
};
root = dfs(0, sz(a)-1);
}
void graphviz_dump(string filename = "graph.dot") {
FILE *f = fopen(filename.c_str(), "w");
fprintf(f, "digraph {\n");
rep(i, 0, cnt) {
node *x = &datalist[i];
fprintf(f, " %lld;\n");
}
rep(i, 0, cnt) {
node *x = &datalist[i];
if (x->ch[0]) fprintf(f, " %lld -> %ld;\n", i, x->ch[0] - &datalist[0]);
if (x->ch[1]) fprintf(f, " %lld -> %ld;\n", i, x->ch[1] - &datalist[0]);
}
fprintf(f, "}\n");
}
};
int32_t main() {
ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
struct value {
int sum = 0, tag = 0, minv = INF, minpos = 0, valid = 1;
value operator+(const value &other) const {
value res;
res.sum = (sum >= INF ? 0 : sum) + (other.sum >= INF ? 0 : other.sum);
res.sum %= P;
if (minv < other.minv) res.minv = minv, res.minpos = minpos;
else res.minv = other.minv, res.minpos = other.minpos;
return res;
}
void set(int pos, int val) {
this->minpos = pos;
this->minv = val;
this->sum = 1;
this->tag = 0;
}
void update(pair<int, int> val, int ql = 0, int qr = 0) {
// first: val, second: valid
if (val.second && this->valid) {
this->tag += val.first;
this->tag %= P;
}
else {
this->valid = 0;
this->sum = 0;
this->tag = 0;
this->minv = INF;
}
}
void pushdown(value &child, int rc) {
child.update({this->tag, 1});
}
void clear() {
if (tag < INF) sum += tag, sum %= P;
else sum = 0, minv = INF;
this->tag = 0;
}
};
int n; cin >> n;
vector<int> a(n);
rep(i, 0, n) cin >> a[i];
segtree<value> t(a);
int ans = 0;
rep(i, 0, n) {
auto it = t.query(0, n-1);
auto leaf = t.query(it.minpos, it.minpos);
ans += leaf.sum;
ans %= P;
t.modify(it.minpos+1, n-1, make_pair(leaf.sum, 1));
t.modify(it.minpos, it.minpos, make_pair(0, 0));
}
cout << ans << endl;
return 0;
}
Alright peeps, EC777game’s got some cool stuff going on. Give it a look if you’re bored. Just sayin’ ec777game!
U888App seems convenient, downloaded, and ready to test it. Gonna give it a spin and see what all the fuss is about. Link in bio! u888app
Kuwwin is…interesting. It’s got a kind of old-school vibe, but the games are surprisingly engaging. Not my usual cup of tea, but I enjoyed it more than I thought I would. Check it out if you’re feeling adventurous: kuwwin
Was looking for something different and stumbled upon lucky804. Not bad at all! Check lucky804 out to see if you like it!
Heard about Hz88game through a friend and figured I’d give it a try. Glad I did! Pretty solid experience overall. Give hz88game a spin, you might find your new favorite.
Yo, q5betgame looks kinda interesting. Anyone got the lowdown on gameplay and payouts? Hollar at me if you got the inside scoop!
Had a bit of trouble with my old account but the support team fixed it instantly. The login process at kastil89login is very secure and fast.
Best slot action I have had in a long time. The graphics are crisp and the win rate feels fair. Big fans of minion178slot over here.
The app is incredibly lightweight and doesn’t lag even on my old phone. It makes the whole experience so much better. Check out 881betapp if you want something stable.
The variety of slots here is insane. I spent the whole night playing and had a great time. Definitely visit okjilicasino if you love slots.
Finally found a place that doesn’t lag during the big moments. The betting options are extensive and the odds are quite competitive. krbettwiner is legit.
This is exactly the kind of place I was searching for all this time. The live dealer tables create such a real atmosphere and the dealers are incredibly friendly. Every transaction is handled with total honesty and speed. It genuinely feels like sitting at a cozy table with old friends enjoying a fun night out. casinoa7