#include <bits/stdc++.h>
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr)
#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
#define TSTS int ttt; cin >> ttt; while(ttt--) solve()
#define all(x) (x).begin(), (x).end()
#define le(vec) vec[vec.size()-1]
#define sz(x) ((int)((x).size()))
#define pb push_back
#define s second
#define f first
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long double, long double> pdd;
const int INF=1e9, MOD=1e9+7, mod=998244353;
const ll LINF=1e18;
void setIO()
{
FAST_IO;
}
void setIO(string s)
{
FAST_IO;
freopen((s+".in").c_str(), "r", stdin);
freopen((s+".out").c_str(), "w", stdout);
}
const int N=1e4+1, Q=101;
int n, l, qr, a[N], c[N], q[Q], cn[N][Q], id;
set<int> st;
int main()
{
setIO();
cin >> n >> l;
FOR(i, 0, n) cin >> a[i];
cin >> qr;
FOR(i, 0, qr)
{
cin >> q[i];
st.insert(q[i]);
}
for(auto x : st) c[x]=id++;
for(int d=1; d+l-1<n; d++)
{
int eq=0;
FOR(in, 0, l)
{
if(a[in]==a[in+d]){
eq++;
}
}
int dif=l-eq;
auto it=st.lower_bound(dif);
if(it!=st.end()){
int idx=c[*it];
cn[0][idx]++;
cn[d][idx]++;
}
for(int i=1; i+d+l-1<n; i++)
{
int j=i+d, e=j+l-1, y=i+l-1;
if(a[j-1]==a[i-1]){
eq--;
}
if(a[e]==a[y]){
eq++;
}
int dif=l-eq;
auto it=st.lower_bound(dif);
if(it!=st.end()){
int idx=c[*it];
cn[i][idx]++;
cn[j][idx]++;
}
}
}
FOR(i, 1, id)
{
FOR(j, 0, n-l+1)
{
cn[j][i]+=cn[j][i-1];
}
}
FOR(i, 0, qr)
{
FOR(j, 0, n-l+1)
{
cout << cn[j][c[q[i]]] << " ";
}
cout << '\n';
}
}
Compilation message
lot.cpp: In function 'void setIO(std::string)':
lot.cpp:32:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
32 | freopen((s+".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lot.cpp:33:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | freopen((s+".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
316 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
2 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
316 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
2 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
24 ms |
1128 KB |
Output is correct |
14 |
Correct |
16 ms |
888 KB |
Output is correct |
15 |
Correct |
7 ms |
860 KB |
Output is correct |
16 |
Correct |
13 ms |
1064 KB |
Output is correct |
17 |
Correct |
10 ms |
996 KB |
Output is correct |
18 |
Correct |
16 ms |
1020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
491 ms |
4304 KB |
Output is correct |
2 |
Correct |
544 ms |
4300 KB |
Output is correct |
3 |
Correct |
248 ms |
4300 KB |
Output is correct |
4 |
Correct |
158 ms |
3512 KB |
Output is correct |
5 |
Correct |
69 ms |
452 KB |
Output is correct |
6 |
Correct |
148 ms |
1212 KB |
Output is correct |
7 |
Correct |
109 ms |
2420 KB |
Output is correct |
8 |
Correct |
190 ms |
3208 KB |
Output is correct |
9 |
Correct |
223 ms |
4004 KB |
Output is correct |
10 |
Correct |
165 ms |
4088 KB |
Output is correct |
11 |
Correct |
19 ms |
712 KB |
Output is correct |
12 |
Correct |
119 ms |
1248 KB |
Output is correct |
13 |
Correct |
96 ms |
460 KB |
Output is correct |
14 |
Correct |
112 ms |
448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
491 ms |
4304 KB |
Output is correct |
2 |
Correct |
544 ms |
4300 KB |
Output is correct |
3 |
Correct |
248 ms |
4300 KB |
Output is correct |
4 |
Correct |
158 ms |
3512 KB |
Output is correct |
5 |
Correct |
69 ms |
452 KB |
Output is correct |
6 |
Correct |
148 ms |
1212 KB |
Output is correct |
7 |
Correct |
109 ms |
2420 KB |
Output is correct |
8 |
Correct |
190 ms |
3208 KB |
Output is correct |
9 |
Correct |
223 ms |
4004 KB |
Output is correct |
10 |
Correct |
165 ms |
4088 KB |
Output is correct |
11 |
Correct |
19 ms |
712 KB |
Output is correct |
12 |
Correct |
119 ms |
1248 KB |
Output is correct |
13 |
Correct |
96 ms |
460 KB |
Output is correct |
14 |
Correct |
112 ms |
448 KB |
Output is correct |
15 |
Correct |
364 ms |
4184 KB |
Output is correct |
16 |
Correct |
154 ms |
2060 KB |
Output is correct |
17 |
Correct |
207 ms |
4080 KB |
Output is correct |
18 |
Correct |
172 ms |
2172 KB |
Output is correct |
19 |
Correct |
158 ms |
2312 KB |
Output is correct |
20 |
Correct |
180 ms |
4348 KB |
Output is correct |
21 |
Correct |
160 ms |
4244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
316 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
2 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
24 ms |
1128 KB |
Output is correct |
14 |
Correct |
16 ms |
888 KB |
Output is correct |
15 |
Correct |
7 ms |
860 KB |
Output is correct |
16 |
Correct |
13 ms |
1064 KB |
Output is correct |
17 |
Correct |
10 ms |
996 KB |
Output is correct |
18 |
Correct |
16 ms |
1020 KB |
Output is correct |
19 |
Correct |
491 ms |
4304 KB |
Output is correct |
20 |
Correct |
544 ms |
4300 KB |
Output is correct |
21 |
Correct |
248 ms |
4300 KB |
Output is correct |
22 |
Correct |
158 ms |
3512 KB |
Output is correct |
23 |
Correct |
69 ms |
452 KB |
Output is correct |
24 |
Correct |
148 ms |
1212 KB |
Output is correct |
25 |
Correct |
109 ms |
2420 KB |
Output is correct |
26 |
Correct |
190 ms |
3208 KB |
Output is correct |
27 |
Correct |
223 ms |
4004 KB |
Output is correct |
28 |
Correct |
165 ms |
4088 KB |
Output is correct |
29 |
Correct |
19 ms |
712 KB |
Output is correct |
30 |
Correct |
119 ms |
1248 KB |
Output is correct |
31 |
Correct |
96 ms |
460 KB |
Output is correct |
32 |
Correct |
112 ms |
448 KB |
Output is correct |
33 |
Correct |
364 ms |
4184 KB |
Output is correct |
34 |
Correct |
154 ms |
2060 KB |
Output is correct |
35 |
Correct |
207 ms |
4080 KB |
Output is correct |
36 |
Correct |
172 ms |
2172 KB |
Output is correct |
37 |
Correct |
158 ms |
2312 KB |
Output is correct |
38 |
Correct |
180 ms |
4348 KB |
Output is correct |
39 |
Correct |
160 ms |
4244 KB |
Output is correct |
40 |
Correct |
1057 ms |
5040 KB |
Output is correct |
41 |
Correct |
13 ms |
836 KB |
Output is correct |
42 |
Correct |
324 ms |
5080 KB |
Output is correct |
43 |
Correct |
257 ms |
4608 KB |
Output is correct |
44 |
Correct |
228 ms |
4684 KB |
Output is correct |
45 |
Correct |
1260 ms |
8128 KB |
Output is correct |
46 |
Correct |
19 ms |
1132 KB |
Output is correct |
47 |
Correct |
879 ms |
8248 KB |
Output is correct |
48 |
Correct |
346 ms |
6284 KB |
Output is correct |
49 |
Correct |
341 ms |
7072 KB |
Output is correct |