Submission #1171587

#TimeUsernameProblemLanguageResultExecution timeMemory
1171587hainam2k9Matryoshka (JOI16_matryoshka)C++20
100 / 100
105 ms7428 KiB
#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 = 2e5+5; const string NAME = ""; struct Query{ int a,b,pos; }query[MAXN]; int n,q,a,b,rs[MAXN]; pair<int,int> p[MAXN]; vector<int> v; bool cmp1(pair<int,int>& a, pair<int,int>& b){ if(a.fi==b.fi) return a.se<b.se; return a.fi>b.fi; } bool cmp2(Query& a, Query& b){ if(a.a==b.a) return a.b<b.b; return a.a>b.a; } 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; for(int i = 1; i<=q; ++i) cin >> query[i].a >> query[i].b, query[i].pos=i; sort(p+1,p+n+1,cmp1); sort(query+1,query+q+1,cmp2); for(int i = 1, j = 1; i<=q; ++i){ while(j<=n&&p[j].fi>=query[i].a){ if(p[j].fi==query[i].a&&p[j].se>query[i].b) break; if(v.empty()||v.back()<=p[j].se) v.pb(p[j].se); else v[ub(v.begin(),v.end(),p[j].se)-v.begin()]=p[j].se; ++j; } if(!v.empty()&&v[0]<=query[i].b) rs[query[i].pos]=ub(v.begin(),v.end(),query[i].b)-v.begin(); } for(int i = 1; i<=q; ++i) cout << rs[i] << "\n"; }

Compilation message (stderr)

matryoshka.cpp: In function 'int main()':
matryoshka.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)
      |            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
matryoshka.cpp:39:45: note: in expansion of macro 'fo'
   39 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
matryoshka.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)
      |                                                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
matryoshka.cpp:39:45: note: in expansion of macro 'fo'
   39 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...