# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
969415 |
2024-04-25T06:29:26 Z |
sano |
Pairs (IOI07_pairs) |
C++14 |
|
0 ms |
0 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<int> suradnice;
For(i, n) {
cin >> p[i];
p[i]--;
suradnice.insert(p[i]);
suradnice.insert(max(p[i] - d, ll(0)));
}
vec<int> sur;
unordered_map<int, int> 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;
| ~~^~~~~~~~~~
pairs.cpp: In function 'int main()':
pairs.cpp:12:12: error: expected primary-expression before 'long'
12 | #define ll long long
| ^~~~
pairs.cpp:89:40: note: in expansion of macro 'll'
89 | suradnice.insert(max(p[i] - d, ll(0)));
| ^~