#include <bits/stdc++.h>
#define tt cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0)
#define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define db long double
#define sz(a) ((int)(a).size())
#define pb push_back
#define pf emplace_front
#define pob pop_back
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define ins emplace
#define mp make_pair
using namespace std;
const int MOD = 1e9+7, MAXN = 1e5+5;
const string NAME = "";
int n,q,x,y,z,cnt=0,rs[MAXN];
int bit1[MAXN<<2],bit2[MAXN<<2];
pair<int,int> p[MAXN];
vector<vector<int>> v;
void update(int pos, int val, int bit[]){
while(pos<=n<<2) bit[pos]+=val, pos+=pos&-pos;
}
int get(int pos, int bit[]){
int rs=0;
while(pos>0) rs+=bit[pos], pos-=pos&-pos;
return rs;
}
void compress(){
vector<int> a;
for(int i = 0; i<sz(v); ++i)
a.pb(v[i][2]), a.pb(v[i][3]);
sort(a.begin(),a.end());
a.resize(unique(a.begin(),a.end())-a.begin());
for(int i = 0; i<sz(v); ++i)
v[i][2]=lb(a.begin(),a.end(),v[i][2])-a.begin()+1,
v[i][3]=lb(a.begin(),a.end(),v[i][3])-a.begin()+1;
}
int main()
{
tt;
if(fopen((NAME + ".INP").c_str(), "r")) fo;
cin >> n >> q;
for(int i = 1; i<=n; ++i){
cin >> p[i].fi >> p[i].se;
v.pb({p[i].fi+p[i].se,1,p[i].fi,p[i].se,0});
}
for(int i = 1; i<=q; ++i){
cin >> x >> y >> z;
v.pb({max(x+y,z),-1,x,y,i});
}
sort(v.begin(),v.end());
compress();
for(int i = sz(v)-1; i>=0; --i){
if(v[i][1]==1) update(v[i][2],1,bit1), update(v[i][3],1,bit2), ++cnt;
else rs[v[i][4]]=cnt-get(v[i][2]-1,bit1)-get(v[i][3]-1,bit2);
}
for(int i = 1; i<=q; ++i)
cout << rs[i] << "\n";
}
컴파일 시 표준 에러 (stderr) 메시지
examination.cpp: In function 'int main()':
examination.cpp:3:19: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:47:45: note: in expansion of macro 'fo'
47 | if(fopen((NAME + ".INP").c_str(), "r")) fo;
| ^~
examination.cpp:3:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:47:45: note: in expansion of macro 'fo'
47 | if(fopen((NAME + ".INP").c_str(), "r")) fo;
| ^~
# | 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... |