#include <bits/stdc++.h>
using namespace std;
#define scd(t) scanf("%d", &t)
#define sclld(t) scanf("%lld", &t)
#define forr(i, j, k) for (int i = j; i < k; i++)
#define frange(i, j) forr(i, 0, j)
#define all(cont) cont.begin(), cont.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef long long int lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<lli> vll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long double ld;
template <class T>
struct BIT
{
int size;
vector<T> bit;
vector<T> vec;
BIT(int n) : size(n), bit(n + 1), vec(n + 1) {}
int lsb(int x)
{
return x & (-x);
}
void set(int id, T v)
{
add(id, v - vec[id]);
}
void add(int id, T v)
{
if (id == 0)
return;
vec[id] += v;
while (id <= size)
{
bit[id] += v;
id += lsb(id);
}
}
T query(int id)
{
T tot = 0;
if (id == 0)
return tot;
while (id >= 1)
{
tot += bit[id];
id -= lsb(id);
}
return tot;
}
};
int main()
{
int n;
scd(n);
vii vec(n);
frange(i, n)
{
scd(vec[i].f);
scd(vec[i].s);
}
sort(all(vec));
int h = 1e5;
BIT<int> bit(h + 1);
int id = 0;
frange(i, n)
{
pii p = vec[i];
id %= p.f;
id++;
bit.add(id, 1);
id += p.s - 1;
if (id > p.f)
{
bit.add(p.f + 1, -1);
bit.add(1, 1);
p.s = (id - p.f);
id = 1;
id += p.s - 1;
}
bit.add(id + 1, -1);
}
lli tot = 0;
forr(i, 1, 7 + 1)
{
lli v = bit.query(i);
// printf("%lld\n", v);
tot += v * (v - 1) / 2;
}
printf("%lld", tot);
}
Compilation message
sails.cpp: In function 'int main()':
sails.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
5 | #define scd(t) scanf("%d", &t)
| ~~~~~^~~~~~~~~~
sails.cpp:75:5: note: in expansion of macro 'scd'
75 | scd(n);
| ^~~
sails.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
5 | #define scd(t) scanf("%d", &t)
| ~~~~~^~~~~~~~~~
sails.cpp:81:9: note: in expansion of macro 'scd'
81 | scd(vec[i].f);
| ^~~
sails.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
5 | #define scd(t) scanf("%d", &t)
| ~~~~~^~~~~~~~~~
sails.cpp:82:9: note: in expansion of macro 'scd'
82 | scd(vec[i].s);
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
1104 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
980 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
980 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
1028 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
1108 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
1236 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9 ms |
1620 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
2004 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
21 ms |
2516 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
25 ms |
2792 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
26 ms |
2900 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |