# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
899751 |
2024-01-07T00:04:52 Z |
trMatherz |
Pairs (IOI07_pairs) |
C++17 |
|
4000 ms |
260592 KB |
#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;
vvvi rbit;
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;
}
void rad(int x, int y, int z, int v){
emax(x, 0); emin(x, 400);
emax(y, 0); emin(y, 400);
emax(z, 0); emin(z, 400);
for(int i = x; i <= 400; i += i & -i)
for(int j = y; j <= 400; j += j & -j)
for(int u = z; u <= 400; u += u & -u)
rbit[i][j][u] += v;
}
int ret(int x, int y, int z){
int ret = 0;
for(int i = x; i; i -= i & -i)
for(int j = y; j; j -= j & -j)
for(int u = z; u; u -= u & -u)
ret += rbit[i][j][u];
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 {
ll an = 0;
vector<array<int, 4>> a(n);
A(u, a){
int x, y, z; cin >> x >> y >> z;
u[0] = x - y - z;
u[1] = x - y + z + 100;
u[2] = x + y - z + 100;
u[3] = x + y + z + 100;
}
rbit = vvvi(401, vvi(401, vi(401, 0)));
sort(all(a));
queue<array<int, 4>> cur;
A(u, a){
cur.push(u);
while(!cur.empty() && u[0] - cur.front()[0] > d) {
rad(cur.front()[1] - d, cur.front()[2] - d, cur.front()[3] - d, -1);
rad(cur.front()[1] + d + 1, cur.front()[2] + d + 1, cur.front()[3] + d + 1, 1);
cur.pop();
}
an += ret(u[1], u[2], u[3]);
rad(u[1] - d, u[2] - d, u[3] - d, 1);
rad(u[1] + d + 1, u[2] + d + 1, u[3] + d + 1, -1);
}
cout << an;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
504 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
604 KB |
Output is correct |
2 |
Correct |
21 ms |
1092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
840 KB |
Output is correct |
2 |
Correct |
36 ms |
1104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
856 KB |
Output is correct |
2 |
Correct |
36 ms |
816 KB |
Output is correct |
3 |
Correct |
44 ms |
836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
856 KB |
Output is correct |
2 |
Correct |
1 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
1744 KB |
Output is correct |
2 |
Correct |
38 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
1736 KB |
Output is correct |
2 |
Correct |
59 ms |
2088 KB |
Output is correct |
3 |
Correct |
51 ms |
2128 KB |
Output is correct |
4 |
Correct |
46 ms |
2128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
1920 KB |
Output is correct |
2 |
Correct |
59 ms |
2128 KB |
Output is correct |
3 |
Correct |
59 ms |
2240 KB |
Output is correct |
4 |
Correct |
58 ms |
2216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
95 ms |
258940 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
181 ms |
260592 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
239 ms |
260432 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4067 ms |
260584 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |