//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vil vector<pil>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e5 + 5;
const double eps = 1e-9;
int seg[MAXN*4], lazy[MAXN*4];
void prop(int l, int r, int k) {
if (lazy[k] == 0) return;
if (l != r) {
lazy[k*2] += lazy[k];
lazy[k*2+1] += lazy[k];
}
seg[k] += lazy[k];
lazy[k] = 0;
}
void upd(int l, int r, int k, int a, int b) {
prop(l, r, k);
if (a > r || l > b) return;
if (a <= l && r <= b) {
lazy[k] += 1;
prop(l, r, k);
return;
}
int m = (l+r) / 2;
upd(l, m, k*2, a, b);
upd(m+1, r, k*2+1, a, b);
seg[k] = min(seg[k*2], seg[k*2+1]);
}
int qry(int l, int r, int k, int a) {
prop(l, r, k);
if (r < a || a < l) return 0;
if (a <= l && r <= a) return seg[k];
int m = (l+r) / 2;
return qry(l, m, k*2, a) + qry(m+1, r, k*2+1, a);
}
int search(int l, int r, int k, int b) {
prop(l, r, k);
if (l == r) return l;
int m = (l+r) / 2;
if (seg[k*2] <= seg[k*2+1] || b <= m)
return search(l, m, k*2, b);
return search(m+1, r, k*2+1, b);
}
pii a[MAXN];
int main() {
int n;
ni(n);
for (int i = 0; i < n; i++) {
int h, k;
scanf("%d %d", &h, &k);
a[i] = mp(h, k);
}
sort(a, a + n);
for (int i = 0; i < n; i++) {
int h, k;
tie(h, k) = a[i];
int st = search(1, MAXN - 1, 1, h);
upd(1, MAXN-1, 1, st, min(st+k-1, h));
if (st+k-1 > h)
upd(1, MAXN-1, 1, 1, st+k-1-h);
}
ll ans = 0;
for (int i = 1; i < MAXN; i++) {
ll val = qry(1,MAXN-1,1,i);
ans += ((val-1)*val) / 2ll;
}
prl(ans);
return 0;
}
Compilation message
sails.cpp: In function 'int main()':
sails.cpp:9:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
#define ni(n) scanf("%d", &(n))
~~~~~^~~~~~~~~~~~
sails.cpp:84:2: note: in expansion of macro 'ni'
ni(n);
^~
sails.cpp:87:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &h, &k);
~~~~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
19 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
19 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
19 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
19 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
21 ms |
508 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
26 ms |
1168 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
44 ms |
1600 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
73 ms |
2424 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
95 ms |
3844 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
115 ms |
4212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
122 ms |
4296 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |