답안 #625004

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
625004 2022-08-09T08:54:14 Z Arnch Worst Reporter 3 (JOI18_worst_reporter3) C++17
100 / 100
419 ms 31236 KB
// oooo
/*
 har chi delet mikhad bebar ~
 gitar o ba khodet nabar! ~
 ;Amoo_Hasan;
*/

#include<bits/stdc++.h>
#pragma GCC optimize("O3,no-stack-protector,unroll-loops")
#pragma GCC target("avx2,fma")

using namespace std;

typedef long long ll;
typedef long double ld;

#define Sz(x) int((x).size())
#define All(x) (x).begin(), (x).end()
#define wtf(x) cout<<#x <<" : " <<x <<endl
#define endl '\n'

constexpr ll inf = 1e18, N = 1e6 + 10, mod = 1e9 + 7, pr = 1000696969;

int a[N], d[N];
int T[N], L[N], R[N];
map<int, pair<int, int> > s;

int main() {
    ios :: sync_with_stdio(0), cin.tie(0);
	
	int n, q; cin >>n >>q;
	for(int i = 1; i <= n; i++) cin >>a[i];

	bool f = 0;
	for(int i = 1; i <= n; i++) {
		if(a[i] > 1) f = 1;
	}
	d[1] = a[1];
	for(int i = 2; i <= n; i++) {
		if(a[i] <= a[i - 1]) {
			d[i] = d[i - 1];
			continue;
		}
		ll cnt = a[i] / d[i - 1];
		if(cnt * d[i - 1] < a[i]) cnt++;
		d[i] = d[i - 1] * cnt;
	}

	vector<int> vc;
	for(int i = 1; i <= n;) {
		if(d[i] > 1e9) {
			i++; continue;
		}
		int ptr = i;
		while(ptr <= n && d[ptr] == d[i]) ptr++;
		s[d[i]] = make_pair(i, ptr - 1);
		vc.push_back(d[i]);
		i = ptr;
	}
	sort(All(vc)), vc.erase(unique(All(vc)), vc.end());

	for(int j = 0; j < q; j++) {
		cin >>T[j] >>L[j] >>R[j];
		int ans = 0;
		for(auto i : vc) {
			if(i > T[j]) break;
			int cnt = (T[j] / i) * i;
			int l = cnt + -s[i].second, r = cnt + -s[i].first;
			if(r < L[j] || l > R[j]) continue;
			if(r >= R[j] && l <= L[j]) {
				ans += R[j] - L[j] + 1;
				continue;
			}
			if(R[j] >= r && L[j] <= l) {
				ans += r - l + 1;
				continue;
			}
			if(r <= R[j]) ans += r - L[j] + 1;
			else ans += R[j] - l + 1;
		}
		cout<<ans + (T[j] >= L[j] && T[j] <= R[j]) <<endl;
	}
		
    return 0;
}

Compilation message

worst_reporter3.cpp: In function 'int main()':
worst_reporter3.cpp:34:7: warning: variable 'f' set but not used [-Wunused-but-set-variable]
   34 |  bool f = 0;
      |       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 219 ms 13316 KB Output is correct
2 Correct 207 ms 13324 KB Output is correct
3 Correct 217 ms 13108 KB Output is correct
4 Correct 199 ms 13136 KB Output is correct
5 Correct 216 ms 13128 KB Output is correct
6 Correct 202 ms 13260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 352 KB Output is correct
6 Correct 1 ms 352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 219 ms 13316 KB Output is correct
2 Correct 207 ms 13324 KB Output is correct
3 Correct 217 ms 13108 KB Output is correct
4 Correct 199 ms 13136 KB Output is correct
5 Correct 216 ms 13128 KB Output is correct
6 Correct 202 ms 13260 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 352 KB Output is correct
12 Correct 1 ms 352 KB Output is correct
13 Correct 215 ms 22112 KB Output is correct
14 Correct 257 ms 27580 KB Output is correct
15 Correct 208 ms 26404 KB Output is correct
16 Correct 243 ms 26828 KB Output is correct
17 Correct 385 ms 31208 KB Output is correct
18 Correct 351 ms 31100 KB Output is correct
19 Correct 396 ms 31092 KB Output is correct
20 Correct 364 ms 31120 KB Output is correct
21 Correct 382 ms 31064 KB Output is correct
22 Correct 380 ms 31236 KB Output is correct
23 Correct 358 ms 31072 KB Output is correct
24 Correct 374 ms 31176 KB Output is correct
25 Correct 240 ms 28572 KB Output is correct
26 Correct 233 ms 28516 KB Output is correct
27 Correct 391 ms 30748 KB Output is correct
28 Correct 410 ms 30924 KB Output is correct
29 Correct 419 ms 30460 KB Output is correct
30 Correct 418 ms 30660 KB Output is correct
31 Correct 406 ms 30824 KB Output is correct
32 Correct 213 ms 27156 KB Output is correct
33 Correct 0 ms 340 KB Output is correct