Submission #198025

# Submission time Handle Problem Language Result Execution time Memory
198025 2020-01-24T14:02:20 Z AMO5 Worst Reporter 3 (JOI18_worst_reporter3) C++
100 / 100
1852 ms 29340 KB
#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

long long INF=LLONG_MAX;

ll n,q,d[511111],per[511111];
ll md=0;
vector < pair<ll, pll> > seg;

void upd(){
	ll cur = d[1], pre = 1;
	per[1] = d[1];
	for(ll i = 2; i <= n; i++){
		ll tm = (cur>=d[i]?1:d[i]/cur+(d[i]%cur?1:0));
		per[i] = tm*cur;
		if(per[i]>cur){
			seg.pb(mp(cur,mp(pre,i-1)));
			pre = i;
			cur = per[i];
		}
	}
	seg.pb(mp(cur,mp(pre,n)));
}

ll solve(ll ti, ll x, ll y){
	ll ans = 0;
	if(ti>=x&&ti<=y)ans++;
	for(int i = 0; i < seg.size(); i++){
		ll cur = seg[i].fi; ll le = seg[i].se.fi; ll ri = seg[i].se.se;
		ll moves = (ti/cur)*cur;
		//cout << i << ' ' << cur << ' ' << le << ' ' << ri << ' ' << moves << endl;
		ll pos_l = -1*ri; ll pos_r = -1*le;
		pos_l += moves; pos_r += moves;
		//cout << ' ' << pos_l << ' ' << pos_r;
		pos_l=max(pos_l,x);
		pos_r=min(pos_r,y);
		//cout << ' ' << pos_l << ' ' << pos_r << endl;
		if(pos_l>=x&&pos_l<=y&&pos_r>=x&&pos_r<=y){
			ans += pos_r-pos_l+1;
		}
	}
	return ans;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	cin >> n >> q;
	for(int i = 1; i <= n; i++){
		cin >> d[i];
		md = max(md,d[i]);
	}
	upd();
	ll ti,le,ri;
	//for(int i = 1; i <= n; i++)cout << per[i] << ' '; 
	//cout << endl;
	while(q--){
		cin >> ti >> le >> ri;
		ll ans = 0;
		ans += solve(ti,le,ri);
		cout << ans << endl;
	}
}	

Compilation message

worst_reporter3.cpp: In function 'll solve(ll, ll, ll)':
worst_reporter3.cpp:43:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < seg.size(); i++){
                 ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1616 ms 26720 KB Output is correct
2 Correct 1615 ms 26696 KB Output is correct
3 Correct 1640 ms 26804 KB Output is correct
4 Correct 1621 ms 26820 KB Output is correct
5 Correct 1616 ms 26860 KB Output is correct
6 Correct 1609 ms 26632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1616 ms 26720 KB Output is correct
2 Correct 1615 ms 26696 KB Output is correct
3 Correct 1640 ms 26804 KB Output is correct
4 Correct 1621 ms 26820 KB Output is correct
5 Correct 1616 ms 26860 KB Output is correct
6 Correct 1609 ms 26632 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 1641 ms 25212 KB Output is correct
14 Correct 1641 ms 26040 KB Output is correct
15 Correct 1620 ms 24340 KB Output is correct
16 Correct 1629 ms 25064 KB Output is correct
17 Correct 1822 ms 29272 KB Output is correct
18 Correct 1802 ms 29292 KB Output is correct
19 Correct 1831 ms 29304 KB Output is correct
20 Correct 1846 ms 28840 KB Output is correct
21 Correct 1815 ms 29324 KB Output is correct
22 Correct 1797 ms 29208 KB Output is correct
23 Correct 1799 ms 29192 KB Output is correct
24 Correct 1809 ms 29260 KB Output is correct
25 Correct 1631 ms 26256 KB Output is correct
26 Correct 1623 ms 26604 KB Output is correct
27 Correct 1799 ms 28896 KB Output is correct
28 Correct 1848 ms 29200 KB Output is correct
29 Correct 1852 ms 28748 KB Output is correct
30 Correct 1839 ms 28952 KB Output is correct
31 Correct 1831 ms 29340 KB Output is correct
32 Correct 1618 ms 25364 KB Output is correct
33 Correct 2 ms 376 KB Output is correct