답안 #838297

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
838297 2023-08-26T13:21:29 Z mat_jur 비밀 (JOI14_secret) C++14
0 / 100
445 ms 4556 KB
#include <bits/stdc++.h>
#ifndef LOCAL 
#include "secret.h"
#else
int Secret(int x, int y) {return x+y;}
#endif
using namespace std;
#ifdef DEBUG
auto&operator<<(auto &o, pair<auto, auto> p) {o << "(" << p.first << ", " << p.second << ")"; return o;}
auto operator<<(auto &o, auto x)->decltype(x.end(), o) {o<<"{"; for(auto e : x) o<<e<<", "; return o<<"}";}
#define debug(X) cerr << "["#X"]: " << X << '\n';
#else 
#define debug(X) ;
#endif
#define ll long long
#define all(v) (v).begin(), (v).end()
#define FOR(i,l,r) for(int i=(l);i<=(r);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define ssize(x) int(x.size())
#define fi first
#define se second

vector<vector<int>> lef, rig; 
vector<int> v;
int n;

void Init(int N, int A[]) {
	v.resize(N);
	n = N;
	REP(i, N) v[i] = A[i];
	function<void(int, int, int)> solve = [&](int l, int r, int d) {
		cerr << d << "   " << l << ' ' << r << '\n';
		if (r == l) {
			return;
		}
		int mid = (l+r)/2;
		if (lef.size() < d+1) {lef.resize(d+1); rig.resize(d+1); lef[d].resize(N); rig[d].resize(N);}
		lef[d][mid-l] = v[mid];
		for (int i = mid-1; i >= l; i--) {
			lef[d][i] = Secret(v[i], lef[d][i+1]);	
		}
		rig[d][mid+1] = v[mid+1];
		FOR(i, mid+2, r) {
			rig[d][i] = Secret(rig[d][i], v[i]);
		}
		solve(l, mid, d+1); solve(mid+1, r, d+1);
	};
	solve(0, N-1, 0);
	debug(lef);
	debug(rig);
}

int Query(int L, int R) {
	debug(lef);
	int l = 0, r = n-1, d = 0;
	while (l < r) {
		int mid = (l+r)/2;
		if (l <= mid && mid < r) return Secret(lef[d][L], rig[d][R]);
		if (r <= mid) r = mid;
		else l = mid+1;
		d++;
	}
	return v[l];
}

#ifdef LOCAL
int main() {
	int n;
	cin >> n;
	int a[n];
	REP(i, n) cin >> a[i];
	Init(n, a);
	int q;
	cin >> q;
	while (q--) {
		int l, r;
		cin >> l >> r;
		cout << Query(l, r) << '\n';
	}

	return 0;
};
#endif

Compilation message

secret.cpp: In lambda function:
secret.cpp:37:18: warning: comparison of integer expressions of different signedness: 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   37 |   if (lef.size() < d+1) {lef.resize(d+1); rig.resize(d+1); lef[d].resize(N); rig[d].resize(N);}
      |       ~~~~~~~~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 107 ms 2384 KB Wrong Answer: Query(222, 254) - expected : 34031541, actual : 587620235.
2 Incorrect 108 ms 2412 KB Wrong Answer: Query(60, 375) - expected : 669221184, actual : 38449312.
3 Incorrect 114 ms 2452 KB Wrong Answer: Query(211, 401) - expected : 674373968, actual : 696690974.
4 Incorrect 379 ms 4556 KB Wrong Answer: Query(90, 497) - expected : 397934825, actual : 846921768.
5 Incorrect 383 ms 4412 KB Wrong Answer: Query(587, 915) - expected : 752404486, actual : 755684692.
6 Incorrect 387 ms 4384 KB Wrong Answer: Query(915, 915) - expected : 282904741, actual : 278446241.
7 Incorrect 445 ms 4360 KB Wrong Answer: Query(84, 976) - expected : 742463504, actual : 704129056.
8 Incorrect 393 ms 4456 KB Wrong Answer: Query(58, 987) - expected : 20022464, actual : 427077896.
9 Incorrect 385 ms 4432 KB Wrong Answer: Query(33, 967) - expected : 676869696, actual : 281940969.
10 Incorrect 387 ms 4368 KB Wrong Answer: Query(116, 961) - expected : 68487362, actual : 68832328.