#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using db = double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;
#define mp make_pair
#define f first
#define s second
#define sz(x) (int)(x).size()
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define R0F(i, a) ROF(i, 0, a)
#define EACH(a, x) for (auto& a : x)
ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); }
ll fdiv(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); }
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T> void remDup(vector<T>& v) { sor(v); v.erase(unique(all(v)), v.end()); }
const int MOD = 1e9 + 7;
const int MX = 1e5 + 10;
const ll INF = 1e18;
int N; vpi S; int tree[4 * MX], lazy[4 * MX];
void pushdown(int x, int l, int r) {
if (lazy[x] == 0) return ; tree[x] += lazy[x];
if (l < r) { lazy[2 * x] += lazy[x], lazy[2 * x + 1] += lazy[x]; } lazy[x] = 0;
}
void update(int x, int l, int r, int tl, int tr) { int mid = (l + r) / 2;
pushdown(x, l, r); if (l > tr || r < tl) return ; if (tl <= l && r <= tr) { lazy[x]++; pushdown(x, l, r); return ; }
update(2 * x, l, mid, tl, tr); update(2 * x + 1, mid + 1, r, tl, tr);
tree[x] = min(tree[2 * x], tree[2 * x + 1]);
}
int query(int x, int l, int r, int tl, int tr) { int mid = (l + r) / 2;
pushdown(x, l, r); if (l > tr || r < tl) return MOD; if (tl <= l && r <= tr) return tree[x];
return min(query(2 * x, l, mid, tl, tr), query(2 * x + 1, mid + 1, r, tl, tr));
}
int getPosition(int x, int l, int r, int val) { int mid = (l + r) / 2;
if (l == r) return l; pushdown(x, l, r); pushdown(2 * x, l, mid); pushdown(2 * x + 1, mid + 1, r);
if (tree[2 * x] <= val) return getPosition(2 * x, l, mid, val);
else if (tree[2 * x + 1] <= val) return getPosition(2 * x + 1, mid + 1, r, val); return N + 1;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> N; S.rsz(N); F0R(i, N) cin >> S[i].f >> S[i].s;
sor(S); EACH(P, S) {
int I = P.f - P.s + 1; int largestVal = query(1, 1, MX, I, I);
int ST1 = getPosition(1, 1, MX, largestVal); int ST2 = min(P.f + 1, getPosition(1, 1, MX, largestVal - 1));
update(1, 1, MX, ST2, P.f); update(1, 1, MX, ST1, ST1 + ST2 + P.s - P.f - 2);
}
ll ans = 0; FOR(i, 1, MX + 1) { ll CUR = query(1, 1, MX, i, i); ans += (CUR * (CUR - 1)) / 2; } cout << ans;
}
Compilation message
sails.cpp: In function 'void pushdown(int, int, int)':
sails.cpp:62:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
62 | if (lazy[x] == 0) return ; tree[x] += lazy[x];
| ^~
sails.cpp:62:32: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
62 | if (lazy[x] == 0) return ; tree[x] += lazy[x];
| ^~~~
sails.cpp: In function 'int getPosition(int, int, int, int)':
sails.cpp:79:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
79 | if (l == r) return l; pushdown(x, l, r); pushdown(2 * x, l, mid); pushdown(2 * x + 1, mid + 1, r);
| ^~
sails.cpp:79:27: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
79 | if (l == r) return l; pushdown(x, l, r); pushdown(2 * x, l, mid); pushdown(2 * x + 1, mid + 1, r);
| ^~~~~~~~
sails.cpp:83:5: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
83 | else if (tree[2 * x + 1] <= val) return getPosition(2 * x + 1, mid + 1, r, val); return N + 1;
| ^~~~
sails.cpp:83:86: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
83 | else if (tree[2 * x + 1] <= val) return getPosition(2 * x + 1, mid + 1, r, val); return N + 1;
| ^~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
332 KB |
Output is correct |
2 |
Correct |
30 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
332 KB |
Output is correct |
2 |
Correct |
30 ms |
368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
364 KB |
Output is correct |
2 |
Correct |
30 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
332 KB |
Output is correct |
2 |
Correct |
30 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
460 KB |
Output is correct |
2 |
Incorrect |
32 ms |
2380 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
44 ms |
972 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
82 ms |
1156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
135 ms |
1732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
199 ms |
3080 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
217 ms |
3072 KB |
Output is correct |
2 |
Correct |
164 ms |
2568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
258 ms |
3140 KB |
Output is correct |
2 |
Correct |
209 ms |
1752 KB |
Output is correct |