Submission #114122

# Submission time Handle Problem Language Result Execution time Memory
114122 2019-05-30T12:46:43 Z shayan_p Worst Reporter 3 (JOI18_worst_reporter3) C++14
100 / 100
999 ms 25560 KB
// High above the clouds there is a rainbow...

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int maxn=5e5+10,mod=1e9+7;
const ll inf=1e18;

ll dp[maxn];

int f(ll a,ll b,ll c,ll d){
    ll A=max(a,c),B=min(b,d);
    return max(int(0),int(B-A));
}
int fnd(int r,ll x){
    int l=0; r++;
    while(r-l>1){
	int mid=(l+r)>>1;
	if(x>=dp[mid]) l=mid;
	else r=mid;
    }
    return l;
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    int n,q;cin>>n>>q;
    for(int i=1;i<=n;i++)
	cin>>dp[i];
    dp[0]=1;
    for(int i=1;i<=n;i++)
	dp[i]=((dp[i]+dp[i-1]-1)/dp[i-1])*dp[i-1];
    while(q--){
	ll t,l,r,pos=-n,ans=0;cin>>t>>l>>r;
	int pt=n;
	while(t){
	    int start=pos;
	    int pt2=fnd(pt,t);
	    pos+=pt-pt2, pt=pt2;
	    ans+=f(start,pos,l,r+1);
	    pos+=(t/dp[pt])*dp[pt], t%=dp[pt];
	}
	ans+=f(pos,pos+pt+1,l,r+1);
	cout<<ans<<"\n";
    }
    return 0;
}
// Deathly mistakes:
//  * Read the problem curfully.
//  * Check maxn.
//  * Overflows.
# Verdict Execution time Memory Grader output
1 Correct 297 ms 22776 KB Output is correct
2 Correct 296 ms 22648 KB Output is correct
3 Correct 293 ms 22776 KB Output is correct
4 Correct 300 ms 22736 KB Output is correct
5 Correct 289 ms 22648 KB Output is correct
6 Correct 283 ms 22784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 356 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 297 ms 22776 KB Output is correct
2 Correct 296 ms 22648 KB Output is correct
3 Correct 293 ms 22776 KB Output is correct
4 Correct 300 ms 22736 KB Output is correct
5 Correct 289 ms 22648 KB Output is correct
6 Correct 283 ms 22784 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 3 ms 356 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 294 ms 21404 KB Output is correct
14 Correct 318 ms 21824 KB Output is correct
15 Correct 276 ms 20636 KB Output is correct
16 Correct 288 ms 20984 KB Output is correct
17 Correct 597 ms 25368 KB Output is correct
18 Correct 592 ms 25560 KB Output is correct
19 Correct 609 ms 25464 KB Output is correct
20 Correct 623 ms 25284 KB Output is correct
21 Correct 640 ms 25364 KB Output is correct
22 Correct 614 ms 25336 KB Output is correct
23 Correct 606 ms 25284 KB Output is correct
24 Correct 628 ms 25504 KB Output is correct
25 Correct 335 ms 22704 KB Output is correct
26 Correct 322 ms 22776 KB Output is correct
27 Correct 952 ms 24900 KB Output is correct
28 Correct 968 ms 25336 KB Output is correct
29 Correct 960 ms 24800 KB Output is correct
30 Correct 992 ms 24900 KB Output is correct
31 Correct 999 ms 25084 KB Output is correct
32 Correct 288 ms 21372 KB Output is correct
33 Correct 2 ms 384 KB Output is correct