Submission #1217729

#TimeUsernameProblemLanguageResultExecution timeMemory
1217729nvc2k8Worst Reporter 3 (JOI18_worst_reporter3)C++20
100 / 100
370 ms11288 KiB
#include <bits/stdc++.h> #define TASK "askdjaksdj" #define endl '\n' #define mp make_pair #define pb push_back #define fi first #define se second #define BIT(i,x) (((i)>>(x))&1) #define FOR(i,a,b) for(int i = (a); i<=(b); i++) #define FORD(i,a,b) for(int i = (a); i>=(b); i--) #define all(C) C.begin(), C.end() using namespace std; using ll = long long; using pii = pair<int,int>; const int INT_LIM = 2147483647; const ll LL_LIM = 9223372036854775807; template <typename X> bool minimize(X &x, const X &y) {if (x>y){x = y; return true;}return false;} template <typename X> bool maximize(X &x, const X &y) {if (x<y){x = y; return true;}return false;} ///------------------------------------------/// int n,q; ll a[500005]; ll f[500005]; void inp() { cin >> n >> q; FOR(i, 1, n) cin >> a[i]; f[1] = a[1]; FOR(i, 2, n) { f[i] = ((a[i]+f[i-1]-1)/f[i-1])*f[i-1]; } } void solve() { auto findl = [&](ll time, ll t)->int { int l = 1, r = n, ret = -1; while (l<=r) { int mid = (l+r)>>1; ll pos = -mid+(time/f[mid])*f[mid]; // if (time==6) cout << mid << ' ' << pos << endl; if (pos<=t) { ret = mid; r = mid-1; } else l = mid+1; } return ret; }; auto findr = [&](ll time, ll t)-> int { int l = 1, r = n, ret = -1; while (l<=r) { int mid = (l+r)>>1; ll pos = -mid+((time/f[mid])*f[mid]); if (pos>=t) { ret = mid; l = mid+1; } else r = mid-1; } return ret; }; FOR(iter, 1, q) { ll t,L,R; cin >> t >> L >> R; int l = findl(t, R), r = findr(t, L); int ans = 0; if (l!=-1 && r!=-1) ans+= (r-l+1); if (t>=L && t<=R) ans++; // cout << l << ' ' << r << endl; cout << ans << endl; } } signed main() { ///--------------------------/// ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); if (fopen(TASK".INP","r")!=NULL) { freopen(TASK".INP","r",stdin); freopen(TASK".OUT","w",stdout); } ///--------------------------/// int NTEST = 1; bool codeforces = 0; if (codeforces) cin >> NTEST; while (NTEST--) { inp(); solve(); } return 0; } ///------------------------------------------///

Compilation message (stderr)

worst_reporter3.cpp: In function 'int main()':
worst_reporter3.cpp:90:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |         freopen(TASK".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
worst_reporter3.cpp:91:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |         freopen(TASK".OUT","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...