-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c334851
commit fdc75a2
Showing
22 changed files
with
1,144 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
cp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
using ll = long long; | ||
using pi = pair<ll, ll>; | ||
using vi = vector<ll>; | ||
using vpi = vector<pi>; | ||
using vb = vector<bool>; | ||
|
||
const ll mod = 1e9 + 7; | ||
|
||
ll binpow(ll x, ll n, ll m) { | ||
assert(n >= 0); | ||
|
||
x %= m; // note: m * m must be less than 2^63 to avoid ll overflow | ||
|
||
ll res = 1; | ||
|
||
while (n > 0) { | ||
if (n % 2 == 1) // if n is odd | ||
|
||
res = res * x % m; | ||
|
||
x = x * x % m; | ||
|
||
n /= 2; // divide by two | ||
} | ||
|
||
return res; | ||
} | ||
|
||
void solve() { | ||
ll n, m; | ||
cin >> n >> m; | ||
|
||
ll orsum = 0; | ||
for (ll i = 0; i < m; i++) { | ||
ll x, y, a; | ||
cin >> x >> y >> a; | ||
orsum |= a; | ||
} | ||
|
||
ll ans = 0; | ||
ll i = 0; | ||
while (orsum > 0) { | ||
if (orsum & 1) ans += binpow(2, n - 1 + i, mod); | ||
ans %= mod; | ||
orsum >>= 1; | ||
i++; | ||
} | ||
|
||
cout << ans << endl; | ||
} | ||
|
||
int main() { | ||
ios_base::sync_with_stdio(false); | ||
cin.tie(NULL); | ||
|
||
ll t; | ||
cin >> t; | ||
while(t--) solve(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
using ll = long long; | ||
using pi = pair<ll, ll>; | ||
using vi = vector<ll>; | ||
using vpi = vector<pi>; | ||
using vb = vector<bool>; | ||
|
||
int main() { | ||
ios_base::sync_with_stdio(false); | ||
cin.tie(NULL); | ||
|
||
const int mod = 998244353; | ||
|
||
ll n, x; | ||
cin >> n >> x; | ||
|
||
vector<vi> power(x + 1, vi(n + 1)); | ||
vector<vi> c(n + 1, vi(n + 1)); | ||
|
||
for (int i = 0; i <= x; i += 1) | ||
for (int j = 0; j <= n; j += 1) | ||
power[i][j] = j ? power[i][j - 1] * i % mod : 1; | ||
for (int i = 0; i <= n; i += 1) | ||
for (int j = 0; j <= i; j += 1) | ||
c[i][j] = j ? (c[i - 1][j - 1] + c[i - 1][j]) % mod : 1; | ||
|
||
vector<vi> dp(n + 1, vi(x + 1)); | ||
|
||
for (int i = 0; i < x + 1; i++) { | ||
dp[1][i] = x - i + 1; | ||
} | ||
|
||
for (int i = 2; i <= n; i++) { | ||
for (int j = x; j >= 1; j--) { | ||
for (int k = 0; k <= i; k++) { | ||
if (j + i - 1 < x + 1) dp[i][j] += ((dp[k][j + i - 1] * c[i][i - k]) % mod * power[i - 1][i - k]) % mod; | ||
dp[i][j] %= mod; | ||
} | ||
} | ||
} | ||
|
||
cout << (power[x][n] + mod - dp[n][1]) % mod << endl; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
using ll = long long; | ||
using pi = pair<ll, ll>; | ||
using vi = vector<ll>; | ||
using vpi = vector<pi>; | ||
using vb = vector<bool>; | ||
|
||
void solve() { | ||
ll n; | ||
cin >> n; | ||
|
||
vi a(n); | ||
for(ll i = 0; i < n; i++) { | ||
cin >> a[i]; | ||
} | ||
|
||
ll mx = 0; | ||
ll cnt = 0; | ||
ll sum = 0; | ||
for (ll i = 0; i < n; i++) { | ||
ll cur = a[i]; | ||
while (cur % 2 == 0) cur /= 2, cnt++; | ||
mx = max(mx, cur); | ||
sum += cur; | ||
} | ||
|
||
cout.precision(62); | ||
cout << ((sum - mx) + mx * pow(2, cnt)) << endl; | ||
} | ||
|
||
int main() { | ||
ios_base::sync_with_stdio(false); | ||
cin.tie(NULL); | ||
|
||
ll t; | ||
cin >> t; | ||
while(t--) solve(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
using ll = long long; | ||
using pi = pair<ll, ll>; | ||
using vi = vector<ll>; | ||
using vpi = vector<pi>; | ||
using vb = vector<bool>; | ||
|
||
int main() { | ||
ios_base::sync_with_stdio(false); | ||
cin.tie(NULL); | ||
|
||
ll n, q; | ||
cin >> n >> q; | ||
|
||
string s; | ||
cin >> s >> ws; | ||
|
||
ll sum = 0; | ||
|
||
for (ll i = 0; i < n - 2; i++) { | ||
if (s[i] == 'a' && s[i + 1] == 'b' && s[i + 2] == 'c') sum++; | ||
} | ||
|
||
for (ll j = 0; j < q; j++) { | ||
ll i; | ||
char c; | ||
cin >> i >> c; | ||
i--; | ||
|
||
ll bsum = 0; | ||
|
||
for (ll k = i - 2; k <= i; k++) { | ||
if (k + 2 >= n || k < 0) continue; | ||
if (s[k] == 'a' && s[k + 1] == 'b' && s[k + 2] == 'c') bsum++; | ||
} | ||
|
||
s[i] = c; | ||
|
||
ll nsum = 0; | ||
|
||
for (ll k = i - 2; k <= i; k++) { | ||
if (k + 2 >= n || k < 0) continue; | ||
if (s[k] == 'a' && s[k + 1] == 'b' && s[k + 2] == 'c') nsum++; | ||
} | ||
|
||
sum += nsum - bsum; | ||
cout << sum << endl; | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
using ll = long long; | ||
using pi = pair<ll, ll>; | ||
using vi = vector<ll>; | ||
using vpi = vector<pi>; | ||
using vb = vector<bool>; | ||
|
||
vb prime(1e6 + 8, true); | ||
|
||
void solve() { | ||
ll n, e; | ||
cin >> n >> e; | ||
|
||
vi a(n); | ||
for(ll i = 0; i < n; i++) { | ||
cin >> a[i]; | ||
} | ||
|
||
vb all1(n); | ||
vb works(n); | ||
vi sum(n); | ||
vi sum2(n); | ||
|
||
ll tot = 0; | ||
|
||
for (ll i = 0; i < n; i++) { | ||
ll last = i - e; | ||
|
||
if(last < 0) { | ||
if (a[i] == 1) { | ||
all1[i] = true; | ||
sum[i] = 1; | ||
} else if (prime[a[i]]) { | ||
works[i] = true; | ||
sum[i] = 1; | ||
} | ||
} else { | ||
if(all1[last]) { | ||
if(a[i] == 1) { | ||
all1[i] = true; | ||
sum[i] = sum[last] + 1; | ||
} else if (prime[a[i]]) { | ||
works[i] = true; | ||
sum[i] = sum[last] + 1; | ||
} | ||
} else if(works[last]) { | ||
if(a[i] == 1) { | ||
works[i] = true; | ||
sum[i] = sum[last]; | ||
sum2[i] = sum2[last] + 1; | ||
} | ||
} | ||
|
||
} | ||
if(!works[i] && !all1[i]) { | ||
if (a[i] == 1) { | ||
all1[i] = true; | ||
sum[i] = 1; | ||
} else if (prime[a[i]]) { | ||
works[i] = true; | ||
sum[i] = max((ll)1, sum2[last] + (ll)1); | ||
tot += sum[i] - 1; | ||
} | ||
} else { | ||
if(works[i] && last >= 0) tot += sum[last]; | ||
} | ||
} | ||
|
||
cout << tot << endl; | ||
} | ||
|
||
int main() { | ||
ios_base::sync_with_stdio(false); | ||
cin.tie(NULL); | ||
|
||
prime[0] = prime[1] = false; | ||
for (ll i = 2; i < (1e6+8); i++) { | ||
if (prime[i] && (long long)i * i < (1e6+8)) { | ||
for (ll j = i * i; j < (1e6+8); j += i) | ||
prime[j] = false; | ||
} | ||
} | ||
|
||
|
||
ll t; | ||
cin >> t; | ||
while(t--) solve(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
using ll = long long; | ||
using pi = pair<ll, ll>; | ||
using vi = vector<ll>; | ||
using vpi = vector<pi>; | ||
using vb = vector<bool>; | ||
|
||
vb prime(1e6 + 8, true); | ||
|
||
void solve() { | ||
ll n, e; | ||
cin >> n >> e; | ||
|
||
vi a(n+1); | ||
for (ll i = 1; i <= n; i++) { | ||
cin >> a[i]; | ||
} | ||
|
||
ll tot = 0; | ||
|
||
for (int i = 1; i <= n; i++) { | ||
for (int k = 1; k <= n; k++) { | ||
if (i + e * k > n) continue; | ||
ll prod = 1; | ||
for (int j = 0; j <= k; j++) { | ||
prod *= a[i + e * j]; | ||
} | ||
|
||
if (prime[prod]) tot++; | ||
} | ||
} | ||
|
||
cout << tot << endl; | ||
} | ||
|
||
int main() { | ||
ios_base::sync_with_stdio(false); | ||
cin.tie(NULL); | ||
prime[0] = prime[1] = false; | ||
for (int i = 2; i < (1e6 + 8); i++) { | ||
if (prime[i] && (long long)i * i < (1e6 + 8)) { | ||
for (int j = i * i; j < (1e6 + 8); j += i) | ||
prime[j] = false; | ||
} | ||
} | ||
|
||
ll t; | ||
cin >> t; | ||
while (t--) solve(); | ||
|
||
return 0; | ||
} |
Oops, something went wrong.