| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1302168 | LmaoLmao | Examination (JOI19_examination) | C++20 | 291 ms | 23024 KiB |
#include <bits/stdc++.h>
#define int long long
#define name "a"
#define fi first
#define se second
using namespace std;
using ll = long long;
using ii = pair<int,int>;
using aa = array<int,4>;
const int N = 2e5+5;
const int MOD = 998244353;
vector<int> nen;
int getnen(int x) {
return lower_bound(nen.begin(),nen.end(),x)-nen.begin()+1;
}
struct BIT {
int F[N];
void update(int pos,int val) {
for(int i=pos;i<N;i+=i & -i) {
F[i]+=val;
}
}
int get(int pos) {
int res=0;
for(int i=pos;i>0;i-=i & -i) {
res+=F[i];
}
return res;
}
} F;
aa a[N];
int ans[N];
bool cmp(aa x,aa y) {
if(x[1]!=y[1]) {
return x[1]>y[1];
} else
if(x[2]!=y[2]) {
return x[2]<y[2];
}
else {
return x[3]<y[3];
}
}
bool cmp1(aa x,aa y) {
if(x[0]!=y[0]) {
return x[0]>y[0];
} else
if(x[1]!=y[1]) {
return x[1]>y[1];
} else
if(x[2]!=y[2]) {
return x[2]>y[2];
}
else {
return x[3]<y[3];
}
}
void DNC(int l,int r) {
if(l==r) return;
int mid = l+r >> 1;
DNC(l,mid);
DNC(mid+1,r);
/*cout << l << ' ' << r << endl;
for(int i=l;i<=r;i++) {
for(int j=0;j<4;j++) cout << a[i][j] << ' ';
cout << endl;
}
cout << ans[1] << endl;
cout << endl;*/
int j=l;
for(int i=mid+1;i<=r;i++) {
if(a[i][3]==0) continue;
while(j<=mid && cmp(a[j],a[i]) ) {
if(a[j][3]==0) F.update(a[j][2],1);
j++;
}
ans[a[i][3]]+=F.get(a[i][2]);
}
for(int i=l;i<j;i++) {
if(a[i][3]==0) F.update(a[i][2],-1);
}
j=l;
vector<aa> b;
for(int i=mid+1;i<=r;i++) {
while(j<=mid && cmp(a[j],a[i]) ) {
b.push_back(a[j]);
j++;
}
b.push_back(a[i]);
}
for(int i=j;i<=mid;i++) {
b.push_back(a[i]);
}
for(int i=l;i<=r;i++) {
a[i]=b[i-l];
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
if (fopen(name".inp","r")) {
freopen(name".inp","r",stdin);
freopen(name".out","w",stdout);
}
int n,q;
cin >> n >> q;
for(int i=1;i<=n;i++) {
cin >> a[i][0] >> a[i][1];
a[i][2]=a[i][0]+a[i][1];
nen.push_back(-a[i][2]);
}
for(int i=n+1;i<=n+q;i++) {
cin >> a[i][0] >> a[i][1] >> a[i][2];
a[i][3]=i-n;
nen.push_back(-a[i][2]);
}
sort(a+1,a+1+n+q,cmp1);
sort(nen.begin(),nen.end());
for(int i=1;i<=n+q;i++) {
a[i][2]=getnen(-a[i][2]);
}
DNC(1,n+q);
for(int i=1;i<=q;i++) {
cout << ans[i] << endl;
}
return 0;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
