Submission #1237289

#TimeUsernameProblemLanguageResultExecution timeMemory
1237289alexandrosOsumnjičeni (COCI21_osumnjiceni)C++20
0 / 110
1095 ms1864 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; bool overlaps(ll l1, ll r1, ll l2, ll r2) { return max(l1, l2) <= min(r1, r2); } bool hasOverlap(const vector<pair<ll, ll>>& intervals, ll newL, ll newR) { for (auto& seg : intervals) if (overlaps(seg.first, seg.second, newL, newR)) return true; return false; } int main() { ll n; scanf("%lld", &n); vector<bool> new_block(n, false); vector<pair<ll, ll>> sofar; sofar.reserve(n); for (int i = 0; i < n; i++) { ll L, R; scanf("%lld %lld", &L, &R); if (hasOverlap(sofar, L, R)) { new_block[i] = true; sofar.clear(); } sofar.emplace_back(L, R); } vector<ll> ps(n+1, 0); for (int i = 0; i < n; i++) { ps[i+1] = ps[i] + (new_block[i] ? 1 : 0); } ll Q; scanf("%lld", &Q); for(int q = 0; q < Q; q++) { ll l, r; scanf("%lld %lld", &l, &r); l--; r--; ll ans = 1 + (ps[r+1] - ps[l+1]); printf("%lld\n", ans); } return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     scanf("%lld", &n);
      |     ~~~~~^~~~~~~~~~~~
Main.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         scanf("%lld %lld", &L, &R);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
Main.cpp:43:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |     scanf("%lld", &Q);
      |     ~~~~~^~~~~~~~~~~~
Main.cpp:46:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |         scanf("%lld %lld", &l, &r);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...