#include <bits/stdc++.h>
using namespace std;
#define Tof_Io ios_base::sync_with_stdio(false);cin.tie(0) , cout.tie(0);
#define pb push_back
#define mk make_pair
#define all(v) v.begin(),v.end()
#define int long long int
#define F first
#define S second
#define tagh2(j) j>>1
#define zarb2(j) j<<1
const int MX=2e4+23,mod=1e9+7,mod1 = 1e9+7;
const long long INF = 1ll << 60;
const int N = 1e4 + 5;
const int Q = 100 + 5;
int inv[MX], fac[MX];
int pwe(int a, int b, int md = mod){int res = 1; while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}
void modplus(int &j,int y){(j+=y)>=mod && (j-=mod);}
bool isprime(int n){bool fl = 1;for (int i = 2; i <= sqrt(n)+1; i++){if(n%i==0){fl = 0;break;}}return fl;}
void printt(bool fl){if(fl==1){cout << "YES";return;}cout << "NO";}
int GCD(int a, int b) {return b?GCD(b,a%b):a;}
int MOD(int a, int b=mod1){ int res = a + b; return (res >= mod? res - mod : res); }
int LCM(int a, int b) {return a/GCD(a,b)*b;}
int lis(vector<int>& v){if (v.size() == 0) {return 0;} vector<int> tail(v.size(), 0); int szgth = 1; tail[0] = v[0]; for (int i = 1; i < v.size(); i++) {auto b = tail.begin(), e = tail.begin() + szgth; auto it = lower_bound(b, e, v[i]); if (it == tail.begin() + szgth){tail[szgth++] = v[i];}else{*it = v[i];}} return szgth;}
int yay(int n){return (1ull << n);}
int C(int n,int r){return fac[n] * inv[r] % mod * inv[n-r] % mod;}
void build(){fac[0] = 1; inv[0] = pwe(fac[0],mod-2);for(int i = 1 ; i< MX ; i ++) {fac[i] = (fac[i-1] * i)%mod;inv[i] = pwe(fac[i],mod-2);}}
int dp[N], ans[Q][N], n, q, a[N], K[N], l, ps[N];
void add(const int k)
{
memset(ps, 0, sizeof ps);
for (int i = 0; i <= n - l; i++) ps[dp[i]]++;
for (int i = 1; i <= l; i++) ps[i] += ps[i - 1];
for (int i = 0; i < q; i++) ans[i][k] = ps[K[i]];
}
int32_t main()
{
cin >> n >> l;
for (int i = 0; i < n; i++) cin >> a[i];
cin >> q;
for (int i = 0; i < q; i++) cin >> K[i];
for (int i = 0; i <= n - l; i++) for (int j = 0; j < l; j++) dp[i] += a[j] != a[j + i];
add(0);
for (int i = 1; i <= n - l; i++)
{
for (int j = n - l; j; j--) dp[j] = dp[j - 1] + (a[i + l - 1] != a[j + l - 1]) - (a[i - 1] != a[j - 1]);
dp[0] = 0;
for (int j = 0; j < l; j++) dp[0] += a[j] != a[j + i];
add(i);
}
for (int i = 0; i < q; i++)
{
for (int j = 0; j <= n - l; j++)
{
cout << ans[i][j] - 1 << ' ';
}
cout << endl;
}
return 0;
}
Compilation message
lot.cpp: In function 'long long int lis(std::vector<long long int>&)':
lot.cpp:24:136: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | int lis(vector<int>& v){if (v.size() == 0) {return 0;} vector<int> tail(v.size(), 0); int szgth = 1; tail[0] = v[0]; for (int i = 1; i < v.size(); i++) {auto b = tail.begin(), e = tail.begin() + szgth; auto it = lower_bound(b, e, v[i]); if (it == tail.begin() + szgth){tail[szgth++] = v[i];}else{*it = v[i];}} return szgth;}
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
312 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
436 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
312 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
436 KB |
Output is correct |
13 |
Correct |
12 ms |
468 KB |
Output is correct |
14 |
Correct |
12 ms |
784 KB |
Output is correct |
15 |
Correct |
11 ms |
640 KB |
Output is correct |
16 |
Correct |
16 ms |
852 KB |
Output is correct |
17 |
Correct |
15 ms |
724 KB |
Output is correct |
18 |
Correct |
15 ms |
804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
197 ms |
576 KB |
Output is correct |
2 |
Correct |
224 ms |
612 KB |
Output is correct |
3 |
Correct |
266 ms |
844 KB |
Output is correct |
4 |
Correct |
322 ms |
704 KB |
Output is correct |
5 |
Correct |
144 ms |
600 KB |
Output is correct |
6 |
Correct |
305 ms |
900 KB |
Output is correct |
7 |
Correct |
170 ms |
632 KB |
Output is correct |
8 |
Correct |
233 ms |
616 KB |
Output is correct |
9 |
Correct |
306 ms |
796 KB |
Output is correct |
10 |
Correct |
310 ms |
640 KB |
Output is correct |
11 |
Correct |
16 ms |
468 KB |
Output is correct |
12 |
Correct |
153 ms |
648 KB |
Output is correct |
13 |
Correct |
180 ms |
644 KB |
Output is correct |
14 |
Correct |
162 ms |
644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
197 ms |
576 KB |
Output is correct |
2 |
Correct |
224 ms |
612 KB |
Output is correct |
3 |
Correct |
266 ms |
844 KB |
Output is correct |
4 |
Correct |
322 ms |
704 KB |
Output is correct |
5 |
Correct |
144 ms |
600 KB |
Output is correct |
6 |
Correct |
305 ms |
900 KB |
Output is correct |
7 |
Correct |
170 ms |
632 KB |
Output is correct |
8 |
Correct |
233 ms |
616 KB |
Output is correct |
9 |
Correct |
306 ms |
796 KB |
Output is correct |
10 |
Correct |
310 ms |
640 KB |
Output is correct |
11 |
Correct |
16 ms |
468 KB |
Output is correct |
12 |
Correct |
153 ms |
648 KB |
Output is correct |
13 |
Correct |
180 ms |
644 KB |
Output is correct |
14 |
Correct |
162 ms |
644 KB |
Output is correct |
15 |
Correct |
170 ms |
644 KB |
Output is correct |
16 |
Correct |
294 ms |
760 KB |
Output is correct |
17 |
Correct |
304 ms |
680 KB |
Output is correct |
18 |
Correct |
320 ms |
896 KB |
Output is correct |
19 |
Correct |
321 ms |
648 KB |
Output is correct |
20 |
Correct |
318 ms |
652 KB |
Output is correct |
21 |
Correct |
321 ms |
844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
312 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
436 KB |
Output is correct |
13 |
Correct |
12 ms |
468 KB |
Output is correct |
14 |
Correct |
12 ms |
784 KB |
Output is correct |
15 |
Correct |
11 ms |
640 KB |
Output is correct |
16 |
Correct |
16 ms |
852 KB |
Output is correct |
17 |
Correct |
15 ms |
724 KB |
Output is correct |
18 |
Correct |
15 ms |
804 KB |
Output is correct |
19 |
Correct |
197 ms |
576 KB |
Output is correct |
20 |
Correct |
224 ms |
612 KB |
Output is correct |
21 |
Correct |
266 ms |
844 KB |
Output is correct |
22 |
Correct |
322 ms |
704 KB |
Output is correct |
23 |
Correct |
144 ms |
600 KB |
Output is correct |
24 |
Correct |
305 ms |
900 KB |
Output is correct |
25 |
Correct |
170 ms |
632 KB |
Output is correct |
26 |
Correct |
233 ms |
616 KB |
Output is correct |
27 |
Correct |
306 ms |
796 KB |
Output is correct |
28 |
Correct |
310 ms |
640 KB |
Output is correct |
29 |
Correct |
16 ms |
468 KB |
Output is correct |
30 |
Correct |
153 ms |
648 KB |
Output is correct |
31 |
Correct |
180 ms |
644 KB |
Output is correct |
32 |
Correct |
162 ms |
644 KB |
Output is correct |
33 |
Correct |
170 ms |
644 KB |
Output is correct |
34 |
Correct |
294 ms |
760 KB |
Output is correct |
35 |
Correct |
304 ms |
680 KB |
Output is correct |
36 |
Correct |
320 ms |
896 KB |
Output is correct |
37 |
Correct |
321 ms |
648 KB |
Output is correct |
38 |
Correct |
318 ms |
652 KB |
Output is correct |
39 |
Correct |
321 ms |
844 KB |
Output is correct |
40 |
Correct |
184 ms |
2868 KB |
Output is correct |
41 |
Correct |
38 ms |
796 KB |
Output is correct |
42 |
Correct |
252 ms |
3100 KB |
Output is correct |
43 |
Correct |
321 ms |
2564 KB |
Output is correct |
44 |
Correct |
322 ms |
2840 KB |
Output is correct |
45 |
Correct |
233 ms |
12220 KB |
Output is correct |
46 |
Correct |
45 ms |
2040 KB |
Output is correct |
47 |
Correct |
363 ms |
12332 KB |
Output is correct |
48 |
Correct |
364 ms |
10564 KB |
Output is correct |
49 |
Correct |
370 ms |
11228 KB |
Output is correct |