Submission #200465

#TimeUsernameProblemLanguageResultExecution timeMemory
200465NucleistWorst Reporter 3 (JOI18_worst_reporter3)C++14
100 / 100
695 ms29656 KiB
#include <bits/stdc++.h> using namespace std; #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) #define debug(x) cerr << " - " << #x << ": " << x << endl; #define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl; #define all(x) (x).begin(),(x).end() #define sz(x) (ll)x.size() #define ll long long #define INF 1000000000 #define MOD 1000000007 #define pb push_back #define ve vector<ll> #define dos pair<ll,ll> #define vedos vector<dos> #define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) struct greateri { template<class T> bool operator()(T const &a, T const &b) const { return a > b; } }; ll dist[500011]; int main() { flash; ll n,q; cin>>n>>q; ve fat; for (ll i = 0; i < n; ++i) { ll yo; cin>>yo; fat.pb(yo); } dist[0]=fat[0]; for (ll i = 1; i < fat.size(); ++i) { ll k = dist[i-1]; ll yo = (fat[i]-1)/k; yo++; ll b = yo*k; dist[i]=b; } while(q--) { ll t,l,r; cin>>t>>l>>r; ll low = 0,high=n-1; ll lowest=-1,highest=-1; ll ans=0; if(t>=l && t<=r)ans++; while(low<=high) { ll mid = (low+high)/2; //debug(mid); ll si = (t/dist[n-mid-1])*dist[n-mid-1]; ll nowi = si-(n-mid); if(nowi>=l) { if(nowi<=r) { lowest=n-mid-1; } high=mid-1; } else { low=mid+1; } } low = 0;high=n-1; while(low<=high) { ll mid = (low+high)/2; ll si = (t/dist[n-mid-1])*dist[n-mid-1]; ll nowi = si-(n-mid); //debugs(mid,nowi); if(nowi<=r) { if(nowi>=l) { highest=n-mid-1; } low=mid+1; } else { high=mid-1; } } //debugs(lowest,highest); if(highest!=-1)ans+=(lowest-highest+1); cout<<ans<<'\n'; } return 0; } //code the AC sol ! // BS/queue/map

Compilation message (stderr)

worst_reporter3.cpp:4:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("O3")
 
worst_reporter3.cpp:5:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("unroll-loops")
 
worst_reporter3.cpp: In function 'int main()':
worst_reporter3.cpp:38:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (ll i = 1; i < fat.size(); ++i)
                 ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...