# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
969418 |
2024-04-25T06:33:27 Z |
sano |
Pairs (IOI07_pairs) |
C++14 |
|
215 ms |
524288 KB |
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<fstream>
#include<algorithm>
#include <iomanip>
#include<map>
#include <set>
#include <math.h>
#include <unordered_map>
#define ll long long
#define For(i, n) for(ll i = 0; i < (ll)n; i++)
#define ffor(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rfor(i, n) for(ll i = (ll)n; i >= (ll)0; i--)
#define rffor(i, a, n) for(ll i = (ll)n; i >= (ll)a; i--)
#define vec vector
#define ff first
#define ss second
#define pb push_back
#define pii pair<ll, ll>
#define NEK 1000000000000000000
#define mod (1e9 + 7)
#define rsz resize
#define prv 4
#define D 8
using namespace std;
class intervalac {
ll n;
vec<ll> l, r, in;
public:
void update(ll s) {
in[s] = in[s * 2] + in[s * 2 + 1];
}
intervalac(vec<ll> a) {
n = 1;
while (n < a.size()) n *= 2;
a.resize(n, 0);
l.resize(2 * n);
r.rsz(2 * n);
in.rsz(2 * n);
For(i, n) {
in[i + n] = a[i];
l[i + n] = i;
r[i + n] = i;
}
rffor(i, 1, (n - 1)) {
l[i] = l[i * 2];
r[i] = r[i * 2 + 1];
update(i);
}
return;
}
void zmen(ll a, ll b) {
a += n;
in[a] += b;
a /= 2;
while (a) {
update(a);
a /= 2;
}
return;
}
ll daj_suc(ll a, ll b, ll s = 1) {
if (a > r[s] || b < l[s]) return 0;
if (a <= l[s] && r[s] <= b) return in[s];
return daj_suc(a, b, s * 2) + daj_suc(a, b, s * 2 + 1);
}
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll r;
cin >> r;
ll n;
cin >> n;
ll d;
cin >> d;
ll m;
cin >> m;
vec<ll> p(n);
set<ll> suradnice;
For(i, n) {
cin >> p[i];
p[i]--;
suradnice.insert(p[i]);
suradnice.insert(max(p[i] - d, (ll)0));
}
vec<ll> sur;
unordered_map<ll, ll> sur_ind;
for (auto i : suradnice) {
sur.push_back(i);
sur_ind[i] = sur.size() - 1;
}
vec<ll> sracka(m);
intervalac seg(sracka);
sort(p.begin(), p.end());
ll ans = 0;
For(i, n) {
ans += seg.daj_suc(sur_ind[max((ll)0, p[i] - d)], sur_ind[p[i]]);
seg.zmen(sur_ind[p[i]], 1);
}
cout << ans << '\n';
return 0;
}
Compilation message
pairs.cpp: In constructor 'intervalac::intervalac(std::vector<long long int>)':
pairs.cpp:38:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | while (n < a.size()) n *= 2;
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
215 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
1372 KB |
Output is correct |
2 |
Correct |
23 ms |
1300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
212 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
204 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
8240 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
19 ms |
1256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
26 ms |
1372 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
67 ms |
15032 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
1116 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
1116 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
1116 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |