Submission #774737

#TimeUsernameProblemLanguageResultExecution timeMemory
774737vjudge1Worst Reporter 3 (JOI18_worst_reporter3)C++17
100 / 100
442 ms7264 KiB
/* #pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target("avx2,fma,bmi,bmi2,sse4.2,popcnt,lzcnt") */ #include <bits/stdc++.h> #define taskname "" #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define int long long #define ll long long #define ld long double #define pb push_back #define ff first #define ss second #define pii pair<int, int> #define vi vector<int> #define vii vector<pii> #define isz(x) (int)x.size() using namespace std; const int mxN = 5e5 + 5; const int mod = 1e9 + 7; const ll oo = 1e18; int n, q, speed[mxN]; void solve() { cin >> n >> q; speed[0] = 1; for(int i = 1; i <= n; ++i) { int val; cin >> val; if(speed[i - 1] == mod) { speed[i] = mod; continue; } int needed = val / speed[i - 1]; if(needed * speed[i - 1] < val) ++needed; if(mod / needed < speed[i - 1]) speed[i] = mod; else speed[i] = speed[i - 1] * needed; } for(int i = 1; i <= q; ++i) { int t, l, r; cin >> t >> l >> r; int tl = 0, tr = n, ansl = -1, ansr = -1; while(tl <= tr) { int mid = (tl + tr) >> 1; if(speed[mid] == -1) tr = mid - 1; else { int len = (t / speed[mid]) * speed[mid] - mid; if(len >= l) tl = mid + 1; else tr = mid - 1; } } if(tr < 0) { cout << 0 << "\n"; continue; } else ansl = tr; tl = 0, tr = n; while(tl <= tr) { int mid = (tl + tr) >> 1; if(speed[mid] == -1) tr = mid - 1; else { int len = (t / speed[mid]) * speed[mid] - mid; // cout << len << " " << t << " " << speed[mid] << endl; if(len <= r) tr = mid - 1; else tl = mid + 1; } } // cout << ansl << " " << tl << endl; if(tl > ansl) cout << 0 << "\n"; else cout << ansl - tl + 1 << "\n"; } } signed main() { #ifndef CDuongg if(fopen(taskname".inp", "r")) assert(freopen(taskname".inp", "r", stdin)), assert(freopen(taskname".out", "w", stdout)); #else freopen("bai3.inp", "r", stdin); freopen("bai3.out", "w", stdout); auto start = chrono::high_resolution_clock::now(); #endif ios_base::sync_with_stdio(false); cin.tie(nullptr); int t = 1; //cin >> t; while(t--) solve(); #ifdef CDuongg auto end = chrono::high_resolution_clock::now(); cout << "\n"; for(int i = 1; i <= 100; ++i) cout << '='; cout << "\nExecution time: " << chrono::duration_cast<chrono::milliseconds> (end - start).count() << "[ms]" << endl; #endif }

Compilation message (stderr)

worst_reporter3.cpp: In function 'void solve()':
worst_reporter3.cpp:43:40: warning: unused variable 'ansr' [-Wunused-variable]
   43 |         int tl = 0, tr = n, ansl = -1, ansr = -1;
      |                                        ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...