#include <iostream> //cin, cout
/*
#include <fstream>
std::ifstream cin ("ex.in");
std::ofstream cout ("ex.out");
*/
// includes
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <unordered_set>
#include <stack>
#include <ext/pb_ds/assoc_container.hpp>
#include <random>
#include <chrono>
//usings
using namespace std;
using namespace __gnu_pbds;
// misc
#define ll long long
#define pb push_back
#define pq priority_queue
#define ub upper_bound
#define lb lower_bound
template<typename T, typename U> bool emin(T &a, const U &b){ return b < a ? a = b, true : false; }
template<typename T, typename U> bool emax(T &a, const U &b){ return b > a ? a = b, true : false; }
typedef uint64_t hash_t;
// vectors
#define vi vector<int>
#define vvi vector<vi>
#define vvvi vector<vvi>
#define vpii vector<pair<int, int>>
#define vvpii vector<vector<pair<int, int>>>
#define vppipi vector<pair<int, pair<int, int>>>
#define vl vector<ll>
#define vvl vector<vl>
#define vvvl vector<vvl>
#define vpll vector<pair<ll, ll>>
#define vb vector<bool>
#define vvb vector<vb>
#define vs vector<string>
#define sz(x) (int)x.size()
#define rz(x,y) x.resize(y)
#define all(x) x.begin(), x.end()
// pairs
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mp make_pair
#define f first
#define s second
// sets
#define si set<int>
#define sl set<ll>
#define ss set<string>
#define in insert
template <class T> using iset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// maps
#define mii map<int, int>
#define mll map<ll, ll>
// loops
#define FR(x, z, y) for (int x = z; x < y; x++)
#define FRe(x, z, y) FR(x, z, y + 1)
#define F(x, y) FR(x, 0, y)
#define Fe(x, y) F(x, y + 1)
#define A(x, y) for(auto &x : y)
vi bit;
void add(int x, int v){
for(x++; x <= 160'000; x += x & -x) bit[x] += v;
}
int get(int x){
int ret = 0;
for(x++; x; x -= x & -x) ret += bit[x];
return ret;
}
int main(){
int b, n, d, m; cin >> b >> n >> d >> m;
if(b == 1){
queue<int> cur;
ll an = 0;
vi a(n);
A(u, a) cin >> u;
sort(all(a));
F(i, n){
cur.push(a[i]);
while(!cur.empty() && a[i] - cur.front() > d) cur.pop();
an += sz(cur) - 1;
}
cout << an;
} else if(b == 2){
vpii a(n);
A(u, a) {
int x, y; cin >> x >> y;
u.f = x - y; u.s = x + y;
}
ll an = 0;
bit = vi(160'001, 0);
sort(all(a));
queue<pii> cur;
F(i, n){
cur.push(a[i]);
while(!cur.empty() && a[i].f - cur.front().f > d) {
add(max(0, cur.front().s - d), -1);
add(min(cur.front().s + d + 1, 159'000), 1);
cur.pop();
}
an += get(a[i].s);
add(max(0, a[i].s - d), 1);
add(min(a[i].s + d + 1, 159'000), -1);
}
cout << an;
} else {
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
600 KB |
Output is correct |
2 |
Correct |
20 ms |
1080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
604 KB |
Output is correct |
2 |
Correct |
32 ms |
1108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
600 KB |
Output is correct |
2 |
Correct |
33 ms |
860 KB |
Output is correct |
3 |
Correct |
31 ms |
824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
856 KB |
Output is correct |
2 |
Correct |
1 ms |
860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
1736 KB |
Output is correct |
2 |
Correct |
47 ms |
3068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
48 ms |
1872 KB |
Output is correct |
2 |
Correct |
47 ms |
2996 KB |
Output is correct |
3 |
Correct |
47 ms |
2920 KB |
Output is correct |
4 |
Correct |
46 ms |
2900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
66 ms |
1724 KB |
Output is correct |
2 |
Correct |
56 ms |
3376 KB |
Output is correct |
3 |
Correct |
56 ms |
3152 KB |
Output is correct |
4 |
Correct |
54 ms |
3152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |