제출 #320962

#제출 시각아이디문제언어결과실행 시간메모리
320962phathnvLottery (CEOI18_lot)C++11
100 / 100
1144 ms12260 KiB
#include <bits/stdc++.h> #define mp make_pair #define X first #define Y second #define taskname "Lottery" using namespace std; typedef long long ll; typedef pair <int, int> ii; const int N = 1e4 + 1; const int Q = 101; int n, l, q, a[N], cnt[Q][N], res[Q][N]; ii query[Q]; void readInput(){ cin >> n >> l; for(int i = 1; i <= n; i++) cin >> a[i]; cin >> q; for(int i = 1; i <= q; i++){ cin >> query[i].X; query[i].Y = i; } } void solve(){ sort(query + 1, query + q + 1); for(int dist = 1; dist <= n - l; dist++){ int dif = 0; for(int i = 1; i <= n - dist; i++){ dif += (a[i] != a[i + dist]); if (i >= l){ int p = lower_bound(query + 1, query + q + 1, mp(dif, 0)) - query; if (p <= q){ cnt[p][i - l + 1]++; cnt[p][i + dist - l + 1]++; } dif -= (a[i - l + 1] != a[i + dist - l + 1]); } } } for(int i = 1; i <= q; i++) for(int j = 1; j <= n - l + 1; j++){ cnt[i][j] += cnt[i - 1][j]; res[query[i].Y][j] = cnt[i][j]; } for(int i = 1; i <= q; i++){ for(int j = 1; j <= n - l + 1; j++) cout << res[i][j] << ' '; cout << endl; } } int main(){ if (fopen(taskname".inp", "r")){ freopen(taskname".inp", "r", stdin); freopen(taskname".out", "w", stdout); } readInput(); solve(); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

lot.cpp: In function 'int main()':
lot.cpp:60:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   60 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
lot.cpp:61:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   61 |         freopen(taskname".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...