problem_id stringlengths 6 6 | buggy_code stringlengths 8 526k ⌀ | fixed_code stringlengths 12 526k ⌀ | labels listlengths 0 15 ⌀ | buggy_submission_id int64 1 1.54M ⌀ | fixed_submission_id int64 2 1.54M ⌀ | user_id stringlengths 10 10 ⌀ | language stringclasses 9
values |
|---|---|---|---|---|---|---|---|
p03178 | // Code by 27.
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <memory.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
const unsigned long long BIGEST = 1000000000000000000 + 1000000000000000000;
const long long BIGER = 1000000000000000000;
const int BIG = 1000000000;
const int MOD = 1000000007;
const long long LMOD = 1000000007;
string st;
int d;
long long f[10001][101][2];
int main() {
memset(f, 0, sizeof(f));
cin >> st >> d;
f[0][0][1] = 1;
/*
for(int i=0;i<=st.size();i++)
{
for(int j=0;j<=d;j++)
{
cout<<f[i][j][0]<<"-"<<f[i][j][1]<<" ";
}
cout<<endl;
}
*/
for (int i = 0; i < st.size(); i++) {
for (int j = 0; j < d; j++) {
for (int k = 0; k < 10; k++) {
// if(i==1)cout<<"!";
// if(j-k>=0)
f[i + 1][j][0] += f[i][(j - k + d * 10) % d][0];
if (k < st[i] - '0')
f[i + 1][j][0] += f[i][(j - k + d * 10) % d][1];
f[i + 1][j][0] %= LMOD;
}
}
for (int j = 0; j < d; j++) {
// if(j-st[i]+'0'>=0)
f[i + 1][j][1] += f[i][(j - st[i] + '0' + d * 10) % d][1];
f[i + 1][j][1] %= LMOD;
}
}
/*
for(int i=0;i<=st.size();i++)
{
for(int j=0;j<=d;j++)
{
cout<<f[i][j][0]<<"-"<<f[i][j][1]<<" ";
}
cout<<endl;
}
*/
cout << (f[st.size()][0][0] + f[st.size() - 1][0][1] + LMOD - 1) % LMOD;
return 0;
} | // Code by 27.
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <memory.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
const unsigned long long BIGEST = 1000000000000000000 + 1000000000000000000;
const long long BIGER = 1000000000000000000;
const int BIG = 1000000000;
const int MOD = 1000000007;
const long long LMOD = 1000000007;
string st;
int d;
long long f[10001][101][2];
int main() {
memset(f, 0, sizeof(f));
cin >> st >> d;
f[0][0][1] = 1;
/*
for(int i=0;i<=st.size();i++)
{
for(int j=0;j<=d;j++)
{
cout<<f[i][j][0]<<"-"<<f[i][j][1]<<" ";
}
cout<<endl;
}
*/
for (int i = 0; i < st.size(); i++) {
for (int j = 0; j < d; j++) {
for (int k = 0; k < 10; k++) {
// if(i==1)cout<<"!";
// if(j-k>=0)
f[i + 1][j][0] += f[i][(j - k + d * 10) % d][0];
if (k < st[i] - '0')
f[i + 1][j][0] += f[i][(j - k + d * 10) % d][1];
f[i + 1][j][0] %= LMOD;
}
}
for (int j = 0; j < d; j++) {
// if(j-st[i]+'0'>=0)
f[i + 1][j][1] += f[i][(j - st[i] + '0' + d * 10) % d][1];
f[i + 1][j][1] %= LMOD;
}
}
/*
for(int i=0;i<=st.size();i++)
{
for(int j=0;j<=d;j++)
{
cout<<f[i][j][0]<<"-"<<f[i][j][1]<<" ";
}
cout<<endl;
}
*/
cout << (f[st.size()][0][0] + f[st.size()][0][1] + LMOD - 1) % LMOD;
return 0;
} | [
"expression.operation.binary.remove"
] | 986,487 | 986,488 | u147008092 | cpp |
p03178 | // Code by 27.
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <memory.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
const unsigned long long BIGEST = 1000000000000000000 + 1000000000000000000;
const long long BIGER = 1000000000000000000;
const int BIG = 1000000000;
const int MOD = 1000000007;
const long long LMOD = 1000000007;
string st;
int d;
long long f[10001][101][2];
int main() {
memset(f, 0, sizeof(f));
cin >> st >> d;
f[0][0][1] = 1;
/*
for(int i=0;i<=st.size();i++)
{
for(int j=0;j<=d;j++)
{
cout<<f[i][j][0]<<"-"<<f[i][j][1]<<" ";
}
cout<<endl;
}
*/
for (int i = 0; i < st.size(); i++) {
for (int j = 0; j < d; j++) {
for (int k = 0; k < 10; k++) {
// if(i==1)cout<<"!";
// if(j-k>=0)
f[i + 1][j][0] += f[i][(j - k + d * 10) % d][0];
if (k < st[i] - '0')
f[i + 1][j][0] += f[i][(j - k + d * 10) % d][1];
f[i + 1][j][1] %= LMOD;
}
}
for (int j = 0; j < d; j++) {
// if(j-st[i]+'0'>=0)
f[i + 1][j][1] += f[i][(j - st[i] + '0' + d * 10) % d][1];
f[i + 1][j][1] %= LMOD;
}
}
/*
for(int i=0;i<=st.size();i++)
{
for(int j=0;j<=d;j++)
{
cout<<f[i][j][0]<<"-"<<f[i][j][1]<<" ";
}
cout<<endl;
}
*/
cout << (f[st.size()][0][0] + f[st.size() - 1][0][1] + LMOD - 1) % LMOD;
return 0;
} | // Code by 27.
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <memory.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
const unsigned long long BIGEST = 1000000000000000000 + 1000000000000000000;
const long long BIGER = 1000000000000000000;
const int BIG = 1000000000;
const int MOD = 1000000007;
const long long LMOD = 1000000007;
string st;
int d;
long long f[10001][101][2];
int main() {
memset(f, 0, sizeof(f));
cin >> st >> d;
f[0][0][1] = 1;
/*
for(int i=0;i<=st.size();i++)
{
for(int j=0;j<=d;j++)
{
cout<<f[i][j][0]<<"-"<<f[i][j][1]<<" ";
}
cout<<endl;
}
*/
for (int i = 0; i < st.size(); i++) {
for (int j = 0; j < d; j++) {
for (int k = 0; k < 10; k++) {
// if(i==1)cout<<"!";
// if(j-k>=0)
f[i + 1][j][0] += f[i][(j - k + d * 10) % d][0];
if (k < st[i] - '0')
f[i + 1][j][0] += f[i][(j - k + d * 10) % d][1];
f[i + 1][j][0] %= LMOD;
}
}
for (int j = 0; j < d; j++) {
// if(j-st[i]+'0'>=0)
f[i + 1][j][1] += f[i][(j - st[i] + '0' + d * 10) % d][1];
f[i + 1][j][1] %= LMOD;
}
}
/*
for(int i=0;i<=st.size();i++)
{
for(int j=0;j<=d;j++)
{
cout<<f[i][j][0]<<"-"<<f[i][j][1]<<" ";
}
cout<<endl;
}
*/
cout << (f[st.size()][0][0] + f[st.size()][0][1] + LMOD - 1) % LMOD;
return 0;
} | [
"literal.number.change",
"assignment.variable.change",
"variable_access.subscript.index.change",
"expression.operation.binary.remove"
] | 986,489 | 986,488 | u147008092 | cpp |
p03178 | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
#define Endl endl
#define mp make_pair
#define rep(N) for (int i = 0; i < N; i++)
#define repj(N) for (int j = 0; j < N; j++)
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define For(I, N) for (int I = 0; I < N; I++)
#define cinone(N) \
int N; \
cin >> N;
#define scanfone(N) \
int N; \
cin >> N;
#define cinng(N, M) \
int N[M]; \
for (int yiuytvnm = 0; yiuytvnm < M; yiuytvnm++) \
cin >> N[yiuytvnm];
#define scanfng(N, M) \
int N[M]; \
for (int qrwuoiq = 0; qrwuoiq < M; qrwuoiq++) \
scanf("%d", &N[qrwuoiq]);
#define over(A) \
{ \
cout << A << endl; \
exit(0); \
}
#define all(A) A.begin(), A.end()
#define ceil(a, b) ((a - 1) / b + 1)
typedef unsigned long long ull;
const int inf = 1039074182;
const int mod = 1e9 + 7;
using namespace std;
char c[10005];
int dp[10005][2][105];
int k;
int n;
int main() {
// freopen("input.txt","r",stdin);
scanf("%s", c);
cin >> k;
n = strlen(c);
for (int i = 0; i < n; i++) {
c[i] -= '0';
}
for (int i = 0; i < c[0]; i++) {
dp[0][0][i % k] = 1;
}
dp[0][1][c[0] % k] = 1;
for (int i = 1; i < n; i++) {
for (int j = 0; j <= 9; j++) {
for (int l = 0; l < k; l++) {
dp[i][0][(l + j) % k] += dp[i - 1][0][l];
dp[i][0][(l + j) % k] %= mod;
}
}
for (int j = 0; j < c[i]; j++) {
for (int l = 0; l < k; l++) {
dp[i][0][(l + j) % k] += dp[i - 1][1][l];
dp[i][0][(l + j) % k] %= mod;
}
}
for (int j = c[i]; j <= c[i]; j++) {
for (int l = 0; l < k; l++) {
dp[i][1][(l + j) % k] += dp[i - 1][1][l];
dp[i][1][(l + j) % k] %= mod;
}
}
}
cout << ((dp[n - 1][0][0] + dp[n - 1][1][0] - 1) % mod + mod) % mod << endl;
// for(int i=1;i<n;i++)
// {
// for(int j=0;j<c[i];j++)
// {
// for(int l=0;l<k;l++)
// {
// for(int o=0;o<2;o++)
// {
// dp[i][0][(l+j)%k]+=dp[i-1][o][l];
// }
// }
// }
// for(int l=0;l<k;l++)
// {
// for(int o=0;o<2;o++)
// {
// dp[i][0][(l+c[i])%k]+=dp[i-1][0][l];
// dp[i][1][(l+c[i])%k]+=dp[i-1][1][l];
// }
// }
// }
// cout<<dp[n-1][0][0]+dp[n-1][1][0]-1<<endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
#define Endl endl
#define mp make_pair
#define rep(N) for (int i = 0; i < N; i++)
#define repj(N) for (int j = 0; j < N; j++)
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define For(I, N) for (int I = 0; I < N; I++)
#define cinone(N) \
int N; \
cin >> N;
#define scanfone(N) \
int N; \
cin >> N;
#define cinng(N, M) \
int N[M]; \
for (int yiuytvnm = 0; yiuytvnm < M; yiuytvnm++) \
cin >> N[yiuytvnm];
#define scanfng(N, M) \
int N[M]; \
for (int qrwuoiq = 0; qrwuoiq < M; qrwuoiq++) \
scanf("%d", &N[qrwuoiq]);
#define over(A) \
{ \
cout << A << endl; \
exit(0); \
}
#define all(A) A.begin(), A.end()
#define ceil(a, b) ((a - 1) / b + 1)
typedef unsigned long long ull;
const int inf = 1039074182;
const int mod = 1e9 + 7;
using namespace std;
char c[10005];
int dp[10005][2][105];
int k;
int n;
int main() {
// freopen("input.txt","r",stdin);
scanf("%s", c);
cin >> k;
n = strlen(c);
for (int i = 0; i < n; i++) {
c[i] -= '0';
}
for (int i = 0; i < c[0]; i++) {
dp[0][0][i % k]++;
}
dp[0][1][c[0] % k] = 1;
for (int i = 1; i < n; i++) {
for (int j = 0; j <= 9; j++) {
for (int l = 0; l < k; l++) {
dp[i][0][(l + j) % k] += dp[i - 1][0][l];
dp[i][0][(l + j) % k] %= mod;
}
}
for (int j = 0; j < c[i]; j++) {
for (int l = 0; l < k; l++) {
dp[i][0][(l + j) % k] += dp[i - 1][1][l];
dp[i][0][(l + j) % k] %= mod;
}
}
for (int j = c[i]; j <= c[i]; j++) {
for (int l = 0; l < k; l++) {
dp[i][1][(l + j) % k] += dp[i - 1][1][l];
dp[i][1][(l + j) % k] %= mod;
}
}
}
cout << ((dp[n - 1][0][0] + dp[n - 1][1][0] - 1) % mod + mod) % mod << endl;
return 0;
} | [] | 986,490 | 986,491 | u303964289 | cpp |
p03178 | #include <bits/stdc++.h>
#define FI first
#define SE second
#define PB push_back
#define ll long long
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ROF(i, a, b) for (int i = b - 1; i >= a; i--)
#define YES(i) cout << (i ? "YES" : "NO") << endl
#define Yes(i) cout << (i ? "Yes" : "No") << endl
#define co(i) cout << (i) << endl
#define fcout cout << fixed << setprecision(10)
#define uni(i) i.erase(unique(i.begin(), i.end()), i.end());
#define all(i) i.begin(), i.end()
#define pint pair<int, int>
#define vint vector<int>
using namespace std;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
// const int MOD=998244353;
ll dp[10001][100];
int main() {
string k;
int d;
cin >> k >> d;
dp[0][0] = 1;
int sum = 0;
FOR(i, 0, k.size()) {
FOR(j, 0, d) {
FOR(jj, 0, 10) { dp[i + 1][(j + jj) % d] += dp[i][j]; }
}
}
ll ans = 0;
FOR(i, 0, k.size()) {
int dgt = k[i] - '0';
FOR(j, 0, dgt) {
ans += dp[k.size() - 1 - i][(d * 1000000 - sum - j) % d];
ans %= MOD;
}
sum += dgt;
}
if (sum % d)
(ans += (MOD - 1)) %= MOD;
co(ans);
}
| #include <bits/stdc++.h>
#define FI first
#define SE second
#define PB push_back
#define ll long long
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ROF(i, a, b) for (int i = b - 1; i >= a; i--)
#define YES(i) cout << (i ? "YES" : "NO") << endl
#define Yes(i) cout << (i ? "Yes" : "No") << endl
#define co(i) cout << (i) << endl
#define fcout cout << fixed << setprecision(10)
#define uni(i) i.erase(unique(i.begin(), i.end()), i.end());
#define all(i) i.begin(), i.end()
#define pint pair<int, int>
#define vint vector<int>
using namespace std;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
// const int MOD=998244353;
ll dp[10001][100];
int main() {
string k;
int d;
cin >> k >> d;
dp[0][0] = 1;
int sum = 0;
FOR(i, 0, k.size()) {
FOR(j, 0, d) {
FOR(jj, 0, 10) { (dp[i + 1][(j + jj) % d] += dp[i][j]) %= MOD; }
}
}
ll ans = 0;
FOR(i, 0, k.size()) {
int dgt = k[i] - '0';
FOR(j, 0, dgt) {
ans += dp[k.size() - 1 - i][(d * 1000000 - sum - j) % d];
ans %= MOD;
}
sum += dgt;
}
if (sum % d)
(ans += (MOD - 1)) %= MOD;
co(ans);
}
| [
"call.arguments.change",
"assignment.change"
] | 986,494 | 986,495 | u094270015 | cpp |
p03178 | #include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^・ω・^=)"
#define mkp make_pair
#define lP pair<ll, ll>
#define iP pair<int, int>
typedef long long ll;
using namespace std;
string K;
vector<int> s;
ll DP[100][2], res;
int D;
int main() {
cin >> K >> D;
s.push_back(0);
for (int i = 0; i != K.size(); ++i)
s.push_back(s[i] + K[i] - '0');
DP[0][0] = DP[0][1] = 1;
res = mod;
--res;
++s.back();
for (int i = K.size(); i; --i) {
for (int j = s[i - 1]; j != s[i]; ++j) {
res += DP[(D - j % D) % D][i & 1];
res %= mod;
}
for (int j = 0; j != D; ++j) {
DP[j][(i - 1) & 1] = 0;
for (int k = 0; k != 10; ++k) {
DP[j][(i - 1) & 1] += DP[(D + j - k) % D][i & 1];
DP[j][(i - 1) & 1] %= mod;
}
}
}
cout << res << endl;
return 0;
} | #include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^・ω・^=)"
#define mkp make_pair
#define lP pair<ll, ll>
#define iP pair<int, int>
typedef long long ll;
using namespace std;
string K;
vector<int> s;
ll DP[100][2], res;
int D;
int main() {
cin >> K >> D;
s.push_back(0);
for (int i = 0; i != K.size(); ++i)
s.push_back(s[i] + K[i] - '0');
DP[0][0] = DP[0][1] = 1;
res = mod;
--res;
++s.back();
for (int i = K.size(); i; --i) {
for (int j = s[i - 1]; j != s[i]; ++j) {
res += DP[(D - j % D) % D][i & 1];
res %= mod;
}
for (int j = 0; j != D; ++j) {
DP[j][(i - 1) & 1] = 0;
for (int k = 0; k != 10; ++k) {
DP[j][(i - 1) & 1] += DP[(D + j - (k % D)) % D][i & 1];
DP[j][(i - 1) & 1] %= mod;
}
}
}
cout << res << endl;
return 0;
} | [
"assignment.change"
] | 986,498 | 986,499 | u015514760 | cpp |
p03178 | #include <bits/stdc++.h>
using namespace std;
#define LL long long
int n, k;
char s[10005];
LL dp[10005][105];
int mod = 1e9 + 7;
int main() {
scanf("%s", &s);
scanf("%d", &k);
n = strlen(s);
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < k; j++) {
dp[i][j] = 0;
for (int d = 0; d < 10; d++) {
dp[i][j] += dp[i - 1][(j - d + k) % k];
}
dp[i][j] %= mod;
// printf(" %d,%d = %lld\n",i,j,dp[i][j]);
}
}
LL ret = 0;
int rem = 0;
for (int i = 0; i < n; i++) {
int dig = s[i] - '0';
for (int j = 0; j < dig; j++) {
ret += dp[n - i - 1][((rem - j) % k + k) % k];
// printf("%d,%d + %lld = %lld\n",i,j,dp[n-i-1][((rem-j)%k+k)%k],ret);
}
ret %= mod;
rem = ((rem - dig) % k + k) % k;
}
if (rem == 0)
ret++;
printf("%lld\n", (ret - 1 + mod) % mod);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define LL long long
int n, k;
char s[10005];
LL dp[10005][105];
int mod = 1e9 + 7;
int main() {
scanf("%s", &s);
scanf("%d", &k);
n = strlen(s);
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < k; j++) {
dp[i][j] = 0;
for (int d = 0; d < 10; d++) {
dp[i][j] += dp[i - 1][((j - d) % k + k) % k];
}
dp[i][j] %= mod;
// printf(" %d,%d = %lld\n",i,j,dp[i][j]);
}
}
LL ret = 0;
int rem = 0;
for (int i = 0; i < n; i++) {
int dig = s[i] - '0';
for (int j = 0; j < dig; j++) {
ret += dp[n - i - 1][((rem - j) % k + k) % k];
// printf("%d,%d + %lld = %lld\n",i,j,dp[n-i-1][((rem-j)%k+k)%k],ret);
}
ret %= mod;
rem = ((rem - dig) % k + k) % k;
}
if (rem == 0)
ret++;
printf("%lld\n", (ret - 1 + mod) % mod);
return 0;
}
| [
"assignment.change"
] | 986,529 | 986,530 | u969930880 | cpp |
p03178 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 10050;
const int M = 100;
const int mod = 1e9 + 7;
int add(int x, int y) {
x += y;
return x >= mod ? x - mod : x;
}
int sub(int x, int y) {
x -= y;
return x < 0 ? x + mod : x;
}
int mul(int x, int y) { return (ll)x * y % mod; }
int dp[N][M];
int main() {
string s;
int k;
cin >> s;
scanf("%i", &k);
dp[0][0] = 1;
for (int i = 1; i <= s.size(); i++)
for (int j = 0; j < k; j++)
for (int d = 0; d <= 9; d++)
dp[i][j] = add(dp[i][j], dp[i - 1][(j - d + k) % k]);
int sum = 0, ans = 0;
int sz = s.size();
for (int i = 0; i < s.size(); i++) {
sz--;
for (int j = 0; j < s[i] - '0'; j++) {
ans = add(ans, dp[sz][(k - ((sum + j) % k)) % k]);
}
sum = (sum + (s[i] - '0')) % k;
}
if (sum == 0)
ans = add(ans, 1);
ans = sub(ans, 1);
printf("%i\n", ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 10050;
const int M = 100;
const int mod = 1e9 + 7;
int add(int x, int y) {
x += y;
return x >= mod ? x - mod : x;
}
int sub(int x, int y) {
x -= y;
return x < 0 ? x + mod : x;
}
int mul(int x, int y) { return (ll)x * y % mod; }
int dp[N][M];
int main() {
string s;
int k;
cin >> s;
scanf("%i", &k);
dp[0][0] = 1;
for (int i = 1; i <= s.size(); i++)
for (int j = 0; j < k; j++)
for (int d = 0; d <= 9; d++)
dp[i][j] = add(dp[i][j], dp[i - 1][(j - d % k + k) % k]);
int sum = 0, ans = 0;
int sz = s.size();
for (int i = 0; i < s.size(); i++) {
sz--;
for (int j = 0; j < s[i] - '0'; j++) {
ans = add(ans, dp[sz][(k - ((sum + j) % k)) % k]);
}
sum = (sum + (s[i] - '0')) % k;
}
if (sum == 0)
ans = add(ans, 1);
ans = sub(ans, 1);
printf("%i\n", ans);
return 0;
} | [
"assignment.change"
] | 986,545 | 986,546 | u939096624 | cpp |
p03178 | #include <bits/stdc++.h>
#define REP(a, b) for (int a = 0; a < b; a++)
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define mp make_pair
#define f first
#define s second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> LL;
typedef vector<int> vi;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const int MAXN = 120;
int DP[1005][105][3];
string k;
short n;
short D, sek;
int rek(short pos, short d, short ter) {
// cout << pos << ' ' << d << ' ' << ter << '\n';
if (pos == n) {
if (ter == 2)
return 0;
if (d == 0)
return 1;
else
return 0;
}
int &ret = DP[pos][d][ter];
if (ret != -1)
return ret;
ret = 0;
if (d == 0)
ret += 1;
if (pos != 0) {
if (ter == 0 || ter == 2)
ret = (ret + rek(pos + 1, d, ter)) % MOD;
else if (ter == 1) {
if (k[pos] - '0' == 0)
ret = (ret + rek(pos + 1, d, 1)) % MOD;
else
ret = (ret + rek(pos + 1, d, 0)) % MOD;
}
}
for (short i = 0; i <= 9; i++) {
// cout << i << " EA\n";
if (ter == 0 || ter == 2) {
sek = (d - i) % D;
if (sek >= 0)
ret = (ret + rek(pos + 1, sek, ter)) % MOD;
else
ret = (ret + rek(pos + 1, sek + D, ter)) % MOD;
} else if (ter == 1) {
if (k[pos] - '0' < i) {
sek = (d - i) % D;
if (sek >= 0)
ret = (ret + rek(pos + 1, sek, 2)) % MOD;
else
ret = (ret + rek(pos + 1, sek + D, 2)) % MOD;
} else if (k[pos] - '0' == i) {
sek = (d - i) % D;
if (sek >= 0)
ret = (ret + rek(pos + 1, sek, 1)) % MOD;
else
ret = (ret + rek(pos + 1, sek + D, 1)) % MOD;
} else {
sek = (d - i) % D;
if (sek >= 0)
ret = (ret + rek(pos + 1, sek, 0)) % MOD;
else
ret = (ret + rek(pos + 1, sek + D, 0)) % MOD;
}
}
}
return ret;
}
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cin >> k;
n = k.size();
cin >> D;
memset(DP, -1, sizeof DP);
cout << rek(0, D, 1) << '\n';
} | #include <bits/stdc++.h>
#define REP(a, b) for (int a = 0; a < b; a++)
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define mp make_pair
#define f first
#define s second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> LL;
typedef vector<int> vi;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const int MAXN = 120;
int DP[10005][105][3];
string k;
short n;
short D, sek;
int rek(short pos, short d, short ter) {
// cout << pos << ' ' << d << ' ' << ter << '\n';
if (pos == n) {
if (ter == 2)
return 0;
if (d == 0)
return 1;
else
return 0;
}
int &ret = DP[pos][d][ter];
if (ret != -1)
return ret;
ret = 0;
if (d == 0)
ret += 1;
if (pos != 0) {
if (ter == 0 || ter == 2)
ret = (ret + rek(pos + 1, d, ter)) % MOD;
else if (ter == 1) {
if (k[pos] - '0' == 0)
ret = (ret + rek(pos + 1, d, 1)) % MOD;
else
ret = (ret + rek(pos + 1, d, 0)) % MOD;
}
}
for (short i = 1; i <= 9; i++) {
// cout << i << " EA\n";
if (ter == 0 || ter == 2) {
sek = (d - i) % D;
if (sek >= 0)
ret = (ret + rek(pos + 1, sek, ter)) % MOD;
else
ret = (ret + rek(pos + 1, sek + D, ter)) % MOD;
} else if (ter == 1) {
if (k[pos] - '0' < i) {
sek = (d - i) % D;
if (sek >= 0)
ret = (ret + rek(pos + 1, sek, 2)) % MOD;
else
ret = (ret + rek(pos + 1, sek + D, 2)) % MOD;
} else if (k[pos] - '0' == i) {
sek = (d - i) % D;
if (sek >= 0)
ret = (ret + rek(pos + 1, sek, 1)) % MOD;
else
ret = (ret + rek(pos + 1, sek + D, 1)) % MOD;
} else {
sek = (d - i) % D;
if (sek >= 0)
ret = (ret + rek(pos + 1, sek, 0)) % MOD;
else
ret = (ret + rek(pos + 1, sek + D, 0)) % MOD;
}
}
}
return ret;
}
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cin >> k;
n = k.size();
cin >> D;
memset(DP, -1, sizeof DP);
cout << rek(0, D, 1) << '\n';
} | [
"literal.number.change",
"variable_declaration.array_dimensions.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one"
] | 986,549 | 986,548 | u073686265 | cpp |
p03178 | #include <bits/stdc++.h>
#define fr(i, n) for (int i = 0; i < (n); ++i)
#define foor(i, a, b) for (int i = (a); i <= (b); ++i)
#define rf(i, n) for (int i = (n); i--;)
#define roof(i, b, a) for (int i = (b); i >= (a); --i)
#define elsif else if
#define all(x) x.begin(), x.end()
#define Sort(x) sort(all(x))
#define Reverse(x) reverse(all(x))
#define PQ priority_queue
#define NP(x) next_permutation(all(x))
#define M_PI 3.14159265358979323846
using namespace std;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef unsigned long long ull;
typedef vector<ull> vu;
typedef vector<vu> vvu;
typedef double dbl;
typedef vector<dbl> vd;
typedef vector<vd> vvd;
typedef string str;
typedef vector<str> vs;
typedef vector<vs> vvs;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef map<int, int> mii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef map<ll, ll> mll;
typedef pair<dbl, dbl> pdd;
typedef vector<pdd> vpdd;
typedef map<dbl, dbl> mdd;
typedef pair<str, str> pss;
typedef vector<pss> vpss;
typedef map<str, str> mss;
typedef pair<int, ll> pil;
typedef vector<pil> vpil;
typedef map<int, ll> mil;
typedef pair<ll, int> pli;
typedef vector<pli> vpli;
typedef map<ll, int> mli;
typedef pair<dbl, int> pdi;
typedef vector<pdi> vpdi;
typedef map<dbl, int> mdi;
template <typename T> vector<T> &operator<<(vector<T> &v, const T t) {
v.push_back(t);
return v;
}
template <typename T> multiset<T> &operator<<(multiset<T> &m, const T t) {
m.insert(t);
return m;
}
template <typename T> set<T> &operator<<(set<T> &s, const T t) {
s.insert(t);
return s;
}
template <typename T> stack<T> &operator<<(stack<T> &s, const T t) {
s.push(t);
return s;
}
template <typename T> stack<T> &operator>>(stack<T> &s, T &t) {
t = s.top();
s.pop();
return s;
}
template <typename T> queue<T> &operator<<(queue<T> &q, const T t) {
q.push(t);
return q;
}
template <typename T> queue<T> &operator>>(queue<T> &q, T &t) {
t = q.front();
q.pop();
return q;
}
template <typename T, typename U>
PQ<T, vector<T>, U> &operator<<(PQ<T, vector<T>, U> &q, const T t) {
q.push(t);
return q;
}
template <typename T, typename U>
istream &operator>>(istream &s, pair<T, U> &p) {
return s >> p.first >> p.second;
}
template <typename T> istream &operator>>(istream &s, vector<T> &v) {
fr(i, v.size()) { s >> v[i]; }
return s;
}
template <typename T, typename U>
ostream &operator<<(ostream &s, const pair<T, U> p) {
return s << p.first << " " << p.second;
}
// template<typename T>ostream&operator<<(ostream&s,const vector<T>v){for(auto
// a:v){s<<a<<endl;}return s;}
template <typename T> ostream &operator<<(ostream &s, const vector<T> v) {
fr(i, v.size()) { i ? s << " " << v[i] : s << v[i]; }
return s;
}
template <typename T> ostream &operator<<(ostream &s, const deque<T> d) {
fr(i, d.size()) { i ? s << " " << d[i] : s << d[i]; }
return s;
}
template <typename T, typename U>
pair<T, U> operator+(pair<T, U> a, pair<T, U> b) {
return {a.first + b.first, a.second + b.second};
}
template <typename T, typename U>
pair<T, U> operator-(pair<T, U> a, pair<T, U> b) {
return {a.first - b.first, a.second - b.second};
}
void print(void) { cout << endl; }
template <typename T> void print(T t) { cout << t << endl; }
template <typename T, typename... U> void print(T &&t, U &&...u) {
cout << t << " ";
print(forward<U>(u)...);
}
bool YN(bool b) {
print(b ? "YES" : "NO");
return b;
}
bool PI(bool b) {
print(b ? "POSSIBLE" : "IMPOSSIBLE");
return b;
}
bool Yn(bool b) {
print(b ? "Yes" : "No");
return b;
}
bool Pi(bool b) {
print(b ? "Possible" : "Impossible");
return b;
}
bool yn(bool b) {
print(b ? "yes" : "no");
return b;
}
bool pi(bool b) {
print(b ? "possible" : "impossible");
return b;
}
const int MD = 1e9 + 7;
template <typename T> str to_string(const T &n) {
ostringstream s;
s << n;
return s.str();
}
template <typename T, typename U>
vector<pair<T, U>> dijkstra(const vector<vector<pair<T, U>>> E, const U s,
const T inf) {
using P = pair<T, U>;
vector<P> d;
fr(i, E.size()) { d << P{inf, i}; }
PQ<P, vector<P>, greater<P>> pq;
pq << (d[s] = P{0, s});
while (pq.size()) {
P a = pq.top();
pq.pop();
U v = a.second;
if (d[v].first >= a.first) {
for (P e : E[v]) {
if (d[v].first + e.first < d[e.second].first) {
d[e.second] = P{d[v].first + e.first, v};
pq << P{d[v].first + e.first, e.second};
}
}
}
}
return d;
}
template <typename T, typename U>
map<U, pair<T, U>> dijkstra(map<U, vector<pair<T, U>>> E, const U s,
const T inf) {
using P = pair<T, U>;
map<U, P> d;
for (pair<U, vector<P>> e : E) {
d[e.first] = P{inf, e.first};
}
PQ<P, vector<P>, greater<P>> pq;
pq << (d[s] = P{0, s});
while (pq.size()) {
P a = pq.top();
pq.pop();
U v = a.second;
if (d[v].first >= a.first) {
for (P e : E[v]) {
if (d[v].first + e.first < d[e.second].first) {
d[e.second] = P{d[v].first + e.first, v};
pq << P{d[v].first + e.first, e.second};
}
}
}
}
return d;
}
template <typename T> T distsq(pair<T, T> a, pair<T, T> b) {
return (a.first - b.first) * (a.first - b.first) +
(a.second - b.second) * (a.second - b.second);
}
template <typename T> T max(const vector<T> a) {
T m = a[0];
for (T e : a) {
m = max(m, e);
}
return m;
}
template <typename T> T min(const vector<T> a) {
T m = a[0];
for (T e : a) {
m = min(m, e);
}
return m;
}
template <typename T> T gcd(const T a, const T b) {
return a ? gcd(b % a, a) : b;
}
template <typename T> T gcd(const vector<T> a) {
T g = a[0];
for (T e : a) {
g = gcd(g, e);
}
return g;
}
template <typename T> vector<T> LIS(const vector<T> A) {
vector<T> B;
for (T a : A) {
auto it = lower_bound(all(B), a);
if (it == B.end()) {
B << a;
} else {
*it = a;
}
}
return B;
}
template <typename T> vector<T> LCS(vector<T> A, vector<T> B) {
int N = A.size(), M = B.size();
vector<vector<pair<int, pii>>> d(N + 1, vector<pair<int, pii>>(M + 1));
fr(i, N) {
fr(j, M) {
if (A[i] == B[j]) {
d[i + 1][j + 1] = {d[i][j].first + 1, {i, j}};
} else {
d[i + 1][j + 1] = max(d[i][j + 1], d[i + 1][j]);
}
}
}
vector<T> r;
for (pii p = {N, M}; d[p.first][p.second].first;
p = d[p.first][p.second].second) {
r << A[d[p.first][p.second].second.first];
}
Reverse(r);
return r;
}
str LCS(str S, str T) {
vector<char> s =
LCS(vector<char>(S.begin(), S.end()), vector<char>(T.begin(), T.end()));
return str(s.begin(), s.end());
}
template <typename T> vector<pair<T, T>> ConvexHull(vector<pair<T, T>> V) {
if (V.size() <= 3) {
return V;
}
Sort(V);
rf(i, V.size() - 1) V << V[i];
vector<pair<T, T>> r;
for (pair<T, T> p : V) {
int s = r.size();
while (s >= 2 &&
(p.second - r[s - 1].second) * (p.first - r[s - 2].first) <
(p.second - r[s - 2].second) * (p.first - r[s - 1].first)) {
r.pop_back();
--s;
}
r << p;
}
r.pop_back();
return r;
}
class UnionFind {
vi p, r, s;
public:
UnionFind(int N) {
p = r = vi(N);
s = vi(N, 1);
fr(i, N) { p[i] = i; }
}
int find(int i) { return p[i] = p[i] == i ? i : find(p[i]); }
void unite(int a, int b) {
if (r[a = find(a)] > r[b = find(b)]) {
swap(a, b);
}
s[b] += s[a];
r[p[a] = b] += r[a] == r[b];
}
bool same(int a, int b) { return find(a) == find(b); }
int size(int x) { return s[find(x)]; }
};
ll strmod(const str &s, const int m) {
ll x = 0;
fr(i, s.size()) { x = (x * 10 + s[i] - 48) % m; }
return x;
}
vvl mul(const vvl &A, const vvl &B, const int m) {
vvl C;
fr(y, A.size()) { C << vl(B[y].size()); }
fr(y, C.size()) {
fr(x, C[y].size()) {
fr(i, A[0].size()) { (C[y][x] += A[y][i] * B[i][x]) %= m; }
}
}
return C;
}
vvl pow(const vvl &A, const ll n, const int m) {
vvl B;
fr(y, A.size()) { B << vl(A.size()); }
if (n == 0) {
fr(i, B.size()) { B[i][i] = 1; }
}
elsif(n % 2) { B = mul(A, pow(A, n - 1, m), m); }
else {
vvl C = pow(A, n / 2, m);
B = mul(C, C, m);
}
return B;
}
ll pow(const ll a, const ll n, const int m) {
ll t;
return n ? (n & 1 ? a >= 0 ? a % m : (m - (-a % m)) % m : 1) *
(t = pow(a, n >> 1, m), t * t % m) % m
: !!a;
}
ll inv(const ll x, const int p) { return pow(x, p - 2, p); }
ll inv(const ll x) { return inv(x, MD); }
vpll fact(const int n, const int p) {
vpll v(n + 1);
v[0].first = 1;
foor(i, 1, n) { v[i].first = v[i - 1].first * i % p; }
v[n].second = inv(v[n].first, p);
roof(i, n, 1) { v[i - 1].second = v[i].second * i % p; }
return v;
}
class Combination {
const vpll f;
const int M;
public:
Combination(int n, int m) : f(fact(n, m)), M(m) {}
Combination(int n) : Combination(n, MD) {}
ll P(int n, int k) {
return n < 0 || k < 0 || n < k ? 0ll : f[n].first * f[n - k].second % M;
}
ll C(int n, int k) { return P(n, k) * f[k].second % M; }
ll H(int n, int k) { return n == 0 && k == 0 ? 1ll : C(n + k - 1, k); }
};
ll C2(const int n) { return (ll)n * ~-n / 2; }
ll sum(const vi a) {
ll s = 0;
for (int e : a) {
s += e;
}
return s;
}
ll sum(const vl a) {
ll s = 0;
for (ll e : a) {
s += e;
}
return s;
}
template <typename T> int MSB(T N) {
int r = -1;
for (; N > 0; N /= 2) {
++r;
}
return r;
}
template <typename T> class SegmentTree {
vector<T> S;
T (*const op)(T a, T b);
const T zero;
const int B;
public:
SegmentTree(int N, T (*f)(T a, T b), const T zero)
: S(1 << MSB(N - 1) + 2, zero), op(f), zero(zero),
B(1 << MSB(N - 1) + 1) {}
SegmentTree(vector<T> v, T (*f)(T a, T b), const T zero)
: SegmentTree(v.size(), f, zero) {
fr(i, v) { S[S.size() / 2 + i] = v[i]; }
roof(i, S.size() / 2 - 1, 1) { S[i] = op(S[i * 2], S[i * 2 + 1]); }
}
T calc(int l, int r) {
l += B;
r += B;
if (l > r) {
return zero;
}
if (l == r) {
return S[l];
}
T L = S[l], R = S[r];
for (; l / 2 < r / 2; l /= 2, r /= 2) {
if (l % 2 == 0) {
L = op(L, S[l + 1]);
}
if (r % 2 == 1) {
R = op(S[r - 1], R);
}
}
return op(L, R);
}
void replace(int i, T x) {
for (S[i += B] = x; i != 1; i /= 2) {
if (i % 2) {
S[i / 2] = op(S[i - 1], S[i]);
} else {
S[i / 2] = op(S[i], S[i + 1]);
}
}
}
void add(int i, T x) { replace(i, op(S[B + i], x)); }
T top() { return S[1]; }
};
ll BITsum(vl &B, int i) {
ll z = 0;
while (i > 0) {
z += B[i];
i -= i & -i;
}
return z;
}
void BITadd(vl &B, int i, ll x) {
while (i < B.size()) {
B[i] += x;
i += i & -i;
}
}
ll fib(const ll n, const int m) {
ll a, b, c, d, A, B, C, D;
a = 1;
b = 0;
c = 0;
d = 1;
rf(i, 63) {
A = a * a + b * c;
B = a * b + b * d;
C = c * a + d * c;
D = c * b + d * d;
if (n >> i & 1) {
a = A;
b = B;
c = C;
d = D;
A = a + b;
B = a;
C = c + d;
D = c;
}
a = A % m;
b = B % m;
c = C % m;
d = D % m;
}
return b;
}
vi primes(int n) {
vb b(n + 1);
vi p;
foor(i, 2, n) {
if (!b[i]) {
p << i;
for (int j = 2 * i; j <= n; j += i) {
b[j] = true;
}
}
}
return p;
}
vb isprime(const int n) {
vb v(n + 1, true);
v[0] = v[1] = false;
foor(i, 2, n) {
if (v[i]) {
for (int j = 2 * i; j <= n; j += i) {
v[j] = false;
}
}
}
return v;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
str K;
cin >> K;
int N = K.size();
int D;
cin >> D;
vvl d(N + 1, vl(D));
int t = 0;
vvi m(D, vi(D));
fr(i, D) {
fr(j, D) { m[i][j] = (i + j) % D; }
}
fr(i, N) {
fr(j, D) {
fr(k, 10) { (d[i + 1][m[j][k]] += d[i][j]) %= MD; }
}
fr(j, K[i] - '0') { (++d[i + 1][m[t][j]]) %= MD; }
t = (t + K[i] - '0') % D;
}
++d[N][t];
print((d[N][0] - 1 + MD) % MD);
return 0;
}
| #include <bits/stdc++.h>
#define fr(i, n) for (int i = 0; i < (n); ++i)
#define foor(i, a, b) for (int i = (a); i <= (b); ++i)
#define rf(i, n) for (int i = (n); i--;)
#define roof(i, b, a) for (int i = (b); i >= (a); --i)
#define elsif else if
#define all(x) x.begin(), x.end()
#define Sort(x) sort(all(x))
#define Reverse(x) reverse(all(x))
#define PQ priority_queue
#define NP(x) next_permutation(all(x))
#define M_PI 3.14159265358979323846
using namespace std;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef unsigned long long ull;
typedef vector<ull> vu;
typedef vector<vu> vvu;
typedef double dbl;
typedef vector<dbl> vd;
typedef vector<vd> vvd;
typedef string str;
typedef vector<str> vs;
typedef vector<vs> vvs;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef map<int, int> mii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef map<ll, ll> mll;
typedef pair<dbl, dbl> pdd;
typedef vector<pdd> vpdd;
typedef map<dbl, dbl> mdd;
typedef pair<str, str> pss;
typedef vector<pss> vpss;
typedef map<str, str> mss;
typedef pair<int, ll> pil;
typedef vector<pil> vpil;
typedef map<int, ll> mil;
typedef pair<ll, int> pli;
typedef vector<pli> vpli;
typedef map<ll, int> mli;
typedef pair<dbl, int> pdi;
typedef vector<pdi> vpdi;
typedef map<dbl, int> mdi;
template <typename T> vector<T> &operator<<(vector<T> &v, const T t) {
v.push_back(t);
return v;
}
template <typename T> multiset<T> &operator<<(multiset<T> &m, const T t) {
m.insert(t);
return m;
}
template <typename T> set<T> &operator<<(set<T> &s, const T t) {
s.insert(t);
return s;
}
template <typename T> stack<T> &operator<<(stack<T> &s, const T t) {
s.push(t);
return s;
}
template <typename T> stack<T> &operator>>(stack<T> &s, T &t) {
t = s.top();
s.pop();
return s;
}
template <typename T> queue<T> &operator<<(queue<T> &q, const T t) {
q.push(t);
return q;
}
template <typename T> queue<T> &operator>>(queue<T> &q, T &t) {
t = q.front();
q.pop();
return q;
}
template <typename T, typename U>
PQ<T, vector<T>, U> &operator<<(PQ<T, vector<T>, U> &q, const T t) {
q.push(t);
return q;
}
template <typename T, typename U>
istream &operator>>(istream &s, pair<T, U> &p) {
return s >> p.first >> p.second;
}
template <typename T> istream &operator>>(istream &s, vector<T> &v) {
fr(i, v.size()) { s >> v[i]; }
return s;
}
template <typename T, typename U>
ostream &operator<<(ostream &s, const pair<T, U> p) {
return s << p.first << " " << p.second;
}
// template<typename T>ostream&operator<<(ostream&s,const vector<T>v){for(auto
// a:v){s<<a<<endl;}return s;}
template <typename T> ostream &operator<<(ostream &s, const vector<T> v) {
fr(i, v.size()) { i ? s << " " << v[i] : s << v[i]; }
return s;
}
template <typename T> ostream &operator<<(ostream &s, const deque<T> d) {
fr(i, d.size()) { i ? s << " " << d[i] : s << d[i]; }
return s;
}
template <typename T, typename U>
pair<T, U> operator+(pair<T, U> a, pair<T, U> b) {
return {a.first + b.first, a.second + b.second};
}
template <typename T, typename U>
pair<T, U> operator-(pair<T, U> a, pair<T, U> b) {
return {a.first - b.first, a.second - b.second};
}
void print(void) { cout << endl; }
template <typename T> void print(T t) { cout << t << endl; }
template <typename T, typename... U> void print(T &&t, U &&...u) {
cout << t << " ";
print(forward<U>(u)...);
}
bool YN(bool b) {
print(b ? "YES" : "NO");
return b;
}
bool PI(bool b) {
print(b ? "POSSIBLE" : "IMPOSSIBLE");
return b;
}
bool Yn(bool b) {
print(b ? "Yes" : "No");
return b;
}
bool Pi(bool b) {
print(b ? "Possible" : "Impossible");
return b;
}
bool yn(bool b) {
print(b ? "yes" : "no");
return b;
}
bool pi(bool b) {
print(b ? "possible" : "impossible");
return b;
}
const int MD = 1e9 + 7;
template <typename T> str to_string(const T &n) {
ostringstream s;
s << n;
return s.str();
}
template <typename T, typename U>
vector<pair<T, U>> dijkstra(const vector<vector<pair<T, U>>> E, const U s,
const T inf) {
using P = pair<T, U>;
vector<P> d;
fr(i, E.size()) { d << P{inf, i}; }
PQ<P, vector<P>, greater<P>> pq;
pq << (d[s] = P{0, s});
while (pq.size()) {
P a = pq.top();
pq.pop();
U v = a.second;
if (d[v].first >= a.first) {
for (P e : E[v]) {
if (d[v].first + e.first < d[e.second].first) {
d[e.second] = P{d[v].first + e.first, v};
pq << P{d[v].first + e.first, e.second};
}
}
}
}
return d;
}
template <typename T, typename U>
map<U, pair<T, U>> dijkstra(map<U, vector<pair<T, U>>> E, const U s,
const T inf) {
using P = pair<T, U>;
map<U, P> d;
for (pair<U, vector<P>> e : E) {
d[e.first] = P{inf, e.first};
}
PQ<P, vector<P>, greater<P>> pq;
pq << (d[s] = P{0, s});
while (pq.size()) {
P a = pq.top();
pq.pop();
U v = a.second;
if (d[v].first >= a.first) {
for (P e : E[v]) {
if (d[v].first + e.first < d[e.second].first) {
d[e.second] = P{d[v].first + e.first, v};
pq << P{d[v].first + e.first, e.second};
}
}
}
}
return d;
}
template <typename T> T distsq(pair<T, T> a, pair<T, T> b) {
return (a.first - b.first) * (a.first - b.first) +
(a.second - b.second) * (a.second - b.second);
}
template <typename T> T max(const vector<T> a) {
T m = a[0];
for (T e : a) {
m = max(m, e);
}
return m;
}
template <typename T> T min(const vector<T> a) {
T m = a[0];
for (T e : a) {
m = min(m, e);
}
return m;
}
template <typename T> T gcd(const T a, const T b) {
return a ? gcd(b % a, a) : b;
}
template <typename T> T gcd(const vector<T> a) {
T g = a[0];
for (T e : a) {
g = gcd(g, e);
}
return g;
}
template <typename T> vector<T> LIS(const vector<T> A) {
vector<T> B;
for (T a : A) {
auto it = lower_bound(all(B), a);
if (it == B.end()) {
B << a;
} else {
*it = a;
}
}
return B;
}
template <typename T> vector<T> LCS(vector<T> A, vector<T> B) {
int N = A.size(), M = B.size();
vector<vector<pair<int, pii>>> d(N + 1, vector<pair<int, pii>>(M + 1));
fr(i, N) {
fr(j, M) {
if (A[i] == B[j]) {
d[i + 1][j + 1] = {d[i][j].first + 1, {i, j}};
} else {
d[i + 1][j + 1] = max(d[i][j + 1], d[i + 1][j]);
}
}
}
vector<T> r;
for (pii p = {N, M}; d[p.first][p.second].first;
p = d[p.first][p.second].second) {
r << A[d[p.first][p.second].second.first];
}
Reverse(r);
return r;
}
str LCS(str S, str T) {
vector<char> s =
LCS(vector<char>(S.begin(), S.end()), vector<char>(T.begin(), T.end()));
return str(s.begin(), s.end());
}
template <typename T> vector<pair<T, T>> ConvexHull(vector<pair<T, T>> V) {
if (V.size() <= 3) {
return V;
}
Sort(V);
rf(i, V.size() - 1) V << V[i];
vector<pair<T, T>> r;
for (pair<T, T> p : V) {
int s = r.size();
while (s >= 2 &&
(p.second - r[s - 1].second) * (p.first - r[s - 2].first) <
(p.second - r[s - 2].second) * (p.first - r[s - 1].first)) {
r.pop_back();
--s;
}
r << p;
}
r.pop_back();
return r;
}
class UnionFind {
vi p, r, s;
public:
UnionFind(int N) {
p = r = vi(N);
s = vi(N, 1);
fr(i, N) { p[i] = i; }
}
int find(int i) { return p[i] = p[i] == i ? i : find(p[i]); }
void unite(int a, int b) {
if (r[a = find(a)] > r[b = find(b)]) {
swap(a, b);
}
s[b] += s[a];
r[p[a] = b] += r[a] == r[b];
}
bool same(int a, int b) { return find(a) == find(b); }
int size(int x) { return s[find(x)]; }
};
ll strmod(const str &s, const int m) {
ll x = 0;
fr(i, s.size()) { x = (x * 10 + s[i] - 48) % m; }
return x;
}
vvl mul(const vvl &A, const vvl &B, const int m) {
vvl C;
fr(y, A.size()) { C << vl(B[y].size()); }
fr(y, C.size()) {
fr(x, C[y].size()) {
fr(i, A[0].size()) { (C[y][x] += A[y][i] * B[i][x]) %= m; }
}
}
return C;
}
vvl pow(const vvl &A, const ll n, const int m) {
vvl B;
fr(y, A.size()) { B << vl(A.size()); }
if (n == 0) {
fr(i, B.size()) { B[i][i] = 1; }
}
elsif(n % 2) { B = mul(A, pow(A, n - 1, m), m); }
else {
vvl C = pow(A, n / 2, m);
B = mul(C, C, m);
}
return B;
}
ll pow(const ll a, const ll n, const int m) {
ll t;
return n ? (n & 1 ? a >= 0 ? a % m : (m - (-a % m)) % m : 1) *
(t = pow(a, n >> 1, m), t * t % m) % m
: !!a;
}
ll inv(const ll x, const int p) { return pow(x, p - 2, p); }
ll inv(const ll x) { return inv(x, MD); }
vpll fact(const int n, const int p) {
vpll v(n + 1);
v[0].first = 1;
foor(i, 1, n) { v[i].first = v[i - 1].first * i % p; }
v[n].second = inv(v[n].first, p);
roof(i, n, 1) { v[i - 1].second = v[i].second * i % p; }
return v;
}
class Combination {
const vpll f;
const int M;
public:
Combination(int n, int m) : f(fact(n, m)), M(m) {}
Combination(int n) : Combination(n, MD) {}
ll P(int n, int k) {
return n < 0 || k < 0 || n < k ? 0ll : f[n].first * f[n - k].second % M;
}
ll C(int n, int k) { return P(n, k) * f[k].second % M; }
ll H(int n, int k) { return n == 0 && k == 0 ? 1ll : C(n + k - 1, k); }
};
ll C2(const int n) { return (ll)n * ~-n / 2; }
ll sum(const vi a) {
ll s = 0;
for (int e : a) {
s += e;
}
return s;
}
ll sum(const vl a) {
ll s = 0;
for (ll e : a) {
s += e;
}
return s;
}
template <typename T> int MSB(T N) {
int r = -1;
for (; N > 0; N /= 2) {
++r;
}
return r;
}
template <typename T> class SegmentTree {
vector<T> S;
T (*const op)(T a, T b);
const T zero;
const int B;
public:
SegmentTree(int N, T (*f)(T a, T b), const T zero)
: S(1 << MSB(N - 1) + 2, zero), op(f), zero(zero),
B(1 << MSB(N - 1) + 1) {}
SegmentTree(vector<T> v, T (*f)(T a, T b), const T zero)
: SegmentTree(v.size(), f, zero) {
fr(i, v) { S[S.size() / 2 + i] = v[i]; }
roof(i, S.size() / 2 - 1, 1) { S[i] = op(S[i * 2], S[i * 2 + 1]); }
}
T calc(int l, int r) {
l += B;
r += B;
if (l > r) {
return zero;
}
if (l == r) {
return S[l];
}
T L = S[l], R = S[r];
for (; l / 2 < r / 2; l /= 2, r /= 2) {
if (l % 2 == 0) {
L = op(L, S[l + 1]);
}
if (r % 2 == 1) {
R = op(S[r - 1], R);
}
}
return op(L, R);
}
void replace(int i, T x) {
for (S[i += B] = x; i != 1; i /= 2) {
if (i % 2) {
S[i / 2] = op(S[i - 1], S[i]);
} else {
S[i / 2] = op(S[i], S[i + 1]);
}
}
}
void add(int i, T x) { replace(i, op(S[B + i], x)); }
T top() { return S[1]; }
};
ll BITsum(vl &B, int i) {
ll z = 0;
while (i > 0) {
z += B[i];
i -= i & -i;
}
return z;
}
void BITadd(vl &B, int i, ll x) {
while (i < B.size()) {
B[i] += x;
i += i & -i;
}
}
ll fib(const ll n, const int m) {
ll a, b, c, d, A, B, C, D;
a = 1;
b = 0;
c = 0;
d = 1;
rf(i, 63) {
A = a * a + b * c;
B = a * b + b * d;
C = c * a + d * c;
D = c * b + d * d;
if (n >> i & 1) {
a = A;
b = B;
c = C;
d = D;
A = a + b;
B = a;
C = c + d;
D = c;
}
a = A % m;
b = B % m;
c = C % m;
d = D % m;
}
return b;
}
vi primes(int n) {
vb b(n + 1);
vi p;
foor(i, 2, n) {
if (!b[i]) {
p << i;
for (int j = 2 * i; j <= n; j += i) {
b[j] = true;
}
}
}
return p;
}
vb isprime(const int n) {
vb v(n + 1, true);
v[0] = v[1] = false;
foor(i, 2, n) {
if (v[i]) {
for (int j = 2 * i; j <= n; j += i) {
v[j] = false;
}
}
}
return v;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
str K;
cin >> K;
int N = K.size();
int D;
cin >> D;
vvl d(N + 1, vl(D));
int t = 0;
vvi m(D, vi(10));
fr(i, D) {
fr(j, 10) { m[i][j] = (i + j) % D; }
}
fr(i, N) {
fr(j, D) {
fr(k, 10) { (d[i + 1][m[j][k]] += d[i][j]) %= MD; }
}
fr(j, K[i] - '0') { (++d[i + 1][m[t][j]]) %= MD; }
t = (t + K[i] - '0') % D;
}
++d[N][t];
print((d[N][0] - 1 + MD) % MD);
return 0;
}
| [] | 986,552 | 986,553 | u283869437 | cpp |
p03182 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll, ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
struct SEG {
ll seg[1 << 19], la[1 << 19];
SEG(void) {
for (int i = 0; i < 1 << 19; i++)
seg[i] = 0, la[i] = 0;
}
void lazy(int l, int r, int k) {
seg[k] += la[k];
if (r - l > 0) {
la[k * 2 + 1] += la[k];
la[k * 2 + 2] += la[k];
}
la[k] = 0;
}
void add(int a, int b, int l, int r, int k, ll x) {
lazy(l, r, k);
if (r < a || b < l)
return;
if (a <= l && r <= b) {
la[k] += x;
lazy(l, r, k);
return;
}
add(a, b, l, (l + r - 1) / 2, k * 2 + 1, x);
add(a, b, (l + r + 1) / 2, r, k * 2 + 2, x);
seg[k] = max(seg[k * 2 + 1], seg[k * 2 + 2]);
}
ll que(int a, int b, int l, int r, int k) {
lazy(l, r, k);
if (r < a || b < l)
return 0;
if (a <= l && r <= b)
return seg[k];
return max(que(a, b, l, (l + r - 1) / 2, k * 2 + 1),
que(a, b, (l + r + 1) / 2, r, k * 2 + 2));
}
};
struct t {
ll a, b, c;
bool operator<(const t &q) const { return a < q.a; }
};
ll n, m, ans;
vector<t> q;
SEG seg;
int main(void) {
scanf("%lld%lld", &n, &m);
for (int i = 0; i < m; i++) {
ll l, r, x;
scanf("%lld%lld%lld", &l, &r, &x);
q.PB(t{l, l - 1, x});
q.PB(t{r + 1, l - 1, -x});
}
sort(q.begin(), q.end());
int p = 0;
for (int i = 1; i <= n; i++) {
while (p < q.size() && q[p].a <= i) {
seg.add(0, q[p].b, 0, (1 << 18) - 1, 0, q[p].c);
p++;
}
ans = max(ans, seg.que(0, i - 1, 0, (1 << 18) - 1, 0));
seg.add(i, i, 0, (1 << 18) - 1, 0, seg.que(0, i - 1, 0, (1 << 18) - 1, 0));
}
printf("%lld\n", ans);
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll, ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
struct SEG {
ll seg[1 << 19], la[1 << 19];
SEG(void) {
for (int i = 0; i < 1 << 19; i++)
seg[i] = 0, la[i] = 0;
}
void lazy(int l, int r, int k) {
seg[k] += la[k];
if (r - l > 0) {
la[k * 2 + 1] += la[k];
la[k * 2 + 2] += la[k];
}
la[k] = 0;
}
void add(int a, int b, int l, int r, int k, ll x) {
lazy(l, r, k);
if (r < a || b < l)
return;
if (a <= l && r <= b) {
la[k] += x;
lazy(l, r, k);
return;
}
add(a, b, l, (l + r - 1) / 2, k * 2 + 1, x);
add(a, b, (l + r + 1) / 2, r, k * 2 + 2, x);
seg[k] = max(seg[k * 2 + 1], seg[k * 2 + 2]);
}
ll que(int a, int b, int l, int r, int k) {
lazy(l, r, k);
if (r < a || b < l)
return -INF;
if (a <= l && r <= b)
return seg[k];
return max(que(a, b, l, (l + r - 1) / 2, k * 2 + 1),
que(a, b, (l + r + 1) / 2, r, k * 2 + 2));
}
};
struct t {
ll a, b, c;
bool operator<(const t &q) const { return a < q.a; }
};
ll n, m, ans;
vector<t> q;
SEG seg;
int main(void) {
scanf("%lld%lld", &n, &m);
for (int i = 0; i < m; i++) {
ll l, r, x;
scanf("%lld%lld%lld", &l, &r, &x);
q.PB(t{l, l - 1, x});
q.PB(t{r + 1, l - 1, -x});
}
sort(q.begin(), q.end());
int p = 0;
for (int i = 1; i <= n; i++) {
while (p < q.size() && q[p].a <= i) {
seg.add(0, q[p].b, 0, (1 << 18) - 1, 0, q[p].c);
p++;
}
ans = max(ans, seg.que(0, i - 1, 0, (1 << 18) - 1, 0));
seg.add(i, i, 0, (1 << 18) - 1, 0, seg.que(0, i - 1, 0, (1 << 18) - 1, 0));
}
printf("%lld\n", ans);
} | [
"function.return_value.change",
"expression.operation.unary.add"
] | 986,691 | 986,692 | u743900647 | cpp |
p03182 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll, ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
struct SEG {
ll seg[1 << 19], la[1 << 19];
SEG(void) {
for (int i = 0; i < 1 << 19; i++)
seg[i] = 0, la[i] = 0;
}
void lazy(int l, int r, int k) {
seg[k] += la[k];
if (r - l > 0) {
la[k * 2 + 1] += la[k];
la[k * 2 + 2] += la[k];
}
la[k] = 0;
}
void add(int a, int b, int l, int r, int k, ll x) {
lazy(l, r, k);
if (r < a || b < l)
return;
if (a <= l && r <= b) {
la[k] += x;
lazy(l, r, k);
return;
}
add(a, b, l, (l + r - 1) / 2, k * 2 + 1, x);
add(a, b, (l + r + 1) / 2, r, k * 2 + 2, x);
seg[k] = max(seg[k * 2 + 1], seg[k * 2 + 2]);
}
ll que(int a, int b, int l, int r, int k) {
lazy(l, r, k);
if (r < a || b < l)
return 0;
if (a <= l && r <= b)
return seg[k];
return max(que(a, b, l, (l + r - 1) / 2, k * 2 + 1),
que(a, b, (l + r + 1) / 2, r, k * 2 + 2));
}
};
struct t {
ll a, b, c;
bool operator<(const t &q) const { return a < q.a; }
};
ll n, m, ans;
vector<t> q;
SEG seg;
int main(void) {
scanf("%lld%lld", &n, &m);
for (int i = 0; i < m; i++) {
ll l, r, x;
scanf("%lld%lld%lld", &l, &r, &x);
q.PB(t{l, l - 1, x});
q.PB(t{r + 1, l - 1, -x});
}
sort(q.begin(), q.end());
int p = 0;
for (int i = 1; i <= n; i++) {
while (p < q.size() && q[p].a <= i) {
seg.add(0, q[p].b, 0, (1 << 18) - 1, 0, q[p].c);
p++;
}
ans = max(ans, seg.que(0, i - 1, 0, (1 << 18) - 1, 0));
seg.add(i, i, 0, (1 << 18) - 1, 0, seg.que(0, i - 1, 0, (1 << 18) - 1, 0));
}
printf("%lld\n", ans);
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll, ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
struct SEG {
ll seg[1 << 19], la[1 << 19];
SEG(void) {
for (int i = 0; i < 1 << 19; i++)
seg[i] = 0, la[i] = 0;
}
void lazy(int l, int r, int k) {
seg[k] += la[k];
if (r - l > 0) {
la[k * 2 + 1] += la[k];
la[k * 2 + 2] += la[k];
}
la[k] = 0;
}
void add(int a, int b, int l, int r, int k, ll x) {
lazy(l, r, k);
if (r < a || b < l)
return;
if (a <= l && r <= b) {
la[k] += x;
lazy(l, r, k);
return;
}
add(a, b, l, (l + r - 1) / 2, k * 2 + 1, x);
add(a, b, (l + r + 1) / 2, r, k * 2 + 2, x);
seg[k] = max(seg[k * 2 + 1], seg[k * 2 + 2]);
}
ll que(int a, int b, int l, int r, int k) {
lazy(l, r, k);
if (r < a || b < l)
return -INF;
if (a <= l && r <= b)
return seg[k];
return max(que(a, b, l, (l + r - 1) / 2, k * 2 + 1),
que(a, b, (l + r + 1) / 2, r, k * 2 + 2));
}
};
struct t {
ll a, b, c;
bool operator<(const t &q) const { return a < q.a; }
};
ll n, m, ans;
vector<t> q;
SEG seg;
int main(void) {
scanf("%lld%lld", &n, &m);
for (int i = 0; i < m; i++) {
ll l, r, x;
scanf("%lld%lld%lld", &l, &r, &x);
q.PB(t{l, l - 1, x});
q.PB(t{r + 1, l - 1, -x});
}
sort(q.begin(), q.end());
int p = 0;
for (int i = 1; i <= n; i++) {
while (p < q.size() && q[p].a <= i) {
seg.add(0, q[p].b, 0, (1 << 18) - 1, 0, q[p].c);
p++;
}
ans = max(ans, seg.que(0, i - 1, 0, (1 << 18) - 1, 0));
seg.add(i, i, 0, (1 << 18) - 1, 0, seg.que(0, i - 1, 0, (1 << 18) - 1, 0));
}
printf("%lld\n", ans);
} | [
"function.return_value.change",
"expression.operation.unary.add"
] | 986,693 | 986,692 | u743900647 | cpp |
p03182 | #include <bits/stdc++.h>
#define ll long long
#define mid ((l + r) >> 1)
#define lc (root << 1)
#define rc (root << 1 | 1)
#define lowbit(x) (x & -x)
using namespace std;
const int N = 2e5 + 7;
const ll inf = 1e18;
int n, m;
ll tre[N << 2], tag[N << 2];
vector<pair<int, int>> vec[N];
void push_down(int root) {
if (tag[root]) {
ll c = tag[root];
tag[lc] += c;
tag[rc] += c;
tre[lc] += c;
tre[rc] += c;
tag[root] = 0;
}
return;
}
ll query(int root, int l, int r, int fl, int fr) {
if (l > fr || r < fl) {
return 0;
}
if (l >= fl && r <= fr) {
return tre[root];
}
push_down(root);
return max(query(lc, l, mid, fl, fr), query(rc, mid + 1, r, fl, fr));
}
void modify(int root, int l, int r, int fl, int fr, ll v) {
if (l > fr || r < fl) {
return;
}
if (l >= fl && r <= fr) {
tre[root] += v;
tag[root] += v;
return;
}
push_down(root);
modify(lc, l, mid, fl, fr, v);
modify(rc, mid + 1, r, fl, fr, v);
tre[root] = max(tre[lc], tre[rc]);
return;
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++) {
int l, r, v;
scanf("%d%d%d", &l, &r, &v);
vec[r].push_back(make_pair(l, v));
}
for (int i = 1; i <= n; i++) {
sort(vec[i].begin(), vec[i].end(), greater<pair<int, int>>());
}
for (int i = 1; i <= n; i++) {
ll res;
res = query(1, 1, n, 1, i);
for (int j = 0; j < vec[i].size(); j++) {
modify(1, 1, n, vec[i][j].first, i, vec[i][j].second);
}
modify(1, 1, n, i, i, res);
}
printf("%lld\n", query(1, 1, n, 1, n));
return 0;
} | #include <bits/stdc++.h>
#define ll long long
#define mid ((l + r) >> 1)
#define lc (root << 1)
#define rc (root << 1 | 1)
#define lowbit(x) (x & -x)
using namespace std;
const int N = 2e5 + 7;
const ll inf = 1e18;
int n, m;
ll tre[N << 2], tag[N << 2];
vector<pair<int, int>> vec[N];
void push_down(int root) {
if (tag[root]) {
ll c = tag[root];
tag[lc] += c;
tag[rc] += c;
tre[lc] += c;
tre[rc] += c;
tag[root] = 0;
}
return;
}
ll query(int root, int l, int r, int fl, int fr) {
if (l > fr || r < fl) {
return 0;
}
if (l >= fl && r <= fr) {
return tre[root];
}
push_down(root);
return max(query(lc, l, mid, fl, fr), query(rc, mid + 1, r, fl, fr));
}
void modify(int root, int l, int r, int fl, int fr, ll v) {
if (l > fr || r < fl) {
return;
}
if (l >= fl && r <= fr) {
tre[root] += v;
tag[root] += v;
return;
}
push_down(root);
modify(lc, l, mid, fl, fr, v);
modify(rc, mid + 1, r, fl, fr, v);
tre[root] = max(tre[lc], tre[rc]);
return;
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++) {
int l, r, v;
scanf("%d%d%d", &l, &r, &v);
vec[r].push_back(make_pair(l, v));
}
for (int i = 1; i <= n; i++) {
sort(vec[i].begin(), vec[i].end(), greater<pair<int, int>>());
}
for (int i = 1; i <= n; i++) {
ll res;
res = query(1, 1, n, 1, i);
for (int j = 0; j < vec[i].size(); j++) {
modify(1, 1, n, vec[i][j].first, i, vec[i][j].second);
}
modify(1, 1, n, i, i, res);
}
printf("%lld\n", max(0ll, query(1, 1, n, 1, n)));
return 0;
} | [
"call.arguments.add",
"call.arguments.change"
] | 986,701 | 986,702 | u171891488 | cpp |
p03182 | #include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 200010;
int n, m, kq, tmp;
int T[4 * N], B[4 * N];
#define goc 1, 0, n
#define lef 2 * s, l, mid
#define rig 2 * s + 1, mid + 1, r
#define mid (l + r) / 2
void trans(int s) {
if (!B[s])
return;
T[2 * s] += B[s];
T[2 * s + 1] += B[s];
B[2 * s] += B[s];
B[2 * s + 1] += B[s];
B[s] = 0;
}
void up(int s, int l, int r, int u, int v, int x) {
if (l > v || u > r)
return;
if (u <= l && r <= v) {
T[s] += x;
B[s] += x;
return;
}
trans(s);
up(lef, u, v, x);
up(rig, u, v, x);
T[s] = max(T[2 * s], T[2 * s + 1]);
}
int get(int s, int l, int r, int u, int v) {
if (l > v || u > r)
return -1e18;
if (u <= l && r <= v)
return T[s];
trans(s);
return max(get(lef, u, v), get(rig, u, v));
}
struct w {
int l, r, x;
} q[N];
vector<int> s[N], t[N];
int l, r, x;
main() {
ios_base::sync_with_stdio(false), cin.tie(nullptr);
cin >> n >> m;
for (int i = 1; i <= m; ++i) {
cin >> l >> r >> x;
q[i] = {l, r, x};
s[l].push_back(i);
t[r].push_back(i);
}
for (int i = 1; i <= 3; ++i) {
for (auto &j : s[i])
up(goc, 0, q[j].l - 1, q[j].x);
tmp = get(goc, 0, i - 1);
kq = max(kq, tmp);
up(goc, i, i, tmp);
for (auto &j : t[i])
up(goc, 0, q[j].l - 1, -q[j].x);
}
cout << kq;
}
/**
f[i] : max value 1->n with ans[i] = 1;
= max f[j] + a[t] for t with l[t]<=i<=r[t];
and !l[t]<=j<=r[t];
n^2 can be done iterating through all posibilities;
we speed up the algo with a seg : seg[i] as f[i]
while iterating through a position : i,
all query with start point at i , we update the range [0,i-1] : a[t];
same as if we meet a end point , we update the range [0,i-1] : -a[t];
*/
| #include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 200010;
int n, m, kq, tmp;
int T[4 * N], B[4 * N];
#define goc 1, 0, n
#define lef 2 * s, l, mid
#define rig 2 * s + 1, mid + 1, r
#define mid (l + r) / 2
void trans(int s) {
if (!B[s])
return;
T[2 * s] += B[s];
T[2 * s + 1] += B[s];
B[2 * s] += B[s];
B[2 * s + 1] += B[s];
B[s] = 0;
}
void up(int s, int l, int r, int u, int v, int x) {
if (l > v || u > r)
return;
if (u <= l && r <= v) {
T[s] += x;
B[s] += x;
return;
}
trans(s);
up(lef, u, v, x);
up(rig, u, v, x);
T[s] = max(T[2 * s], T[2 * s + 1]);
}
int get(int s, int l, int r, int u, int v) {
if (l > v || u > r)
return -1e18;
if (u <= l && r <= v)
return T[s];
trans(s);
return max(get(lef, u, v), get(rig, u, v));
}
struct w {
int l, r, x;
} q[N];
vector<int> s[N], t[N];
int l, r, x;
main() {
ios_base::sync_with_stdio(false), cin.tie(nullptr);
cin >> n >> m;
for (int i = 1; i <= m; ++i) {
cin >> l >> r >> x;
q[i] = {l, r, x};
s[l].push_back(i);
t[r].push_back(i);
}
for (int i = 1; i <= n; ++i) {
for (auto &j : s[i])
up(goc, 0, q[j].l - 1, q[j].x);
tmp = get(goc, 0, i - 1);
kq = max(kq, tmp);
up(goc, i, i, tmp);
for (auto &j : t[i])
up(goc, 0, q[j].l - 1, -q[j].x);
}
cout << kq;
}
/**
f[i] : max value 1->n with ans[i] = 1;
= max f[j] + a[t] for t with l[t]<=i<=r[t];
and !l[t]<=j<=r[t];
n^2 can be done iterating through all posibilities;
we speed up the algo with a seg : seg[i] as f[i]
while iterating through a position : i,
all query with start point at i , we update the range [0,i-1] : a[t];
same as if we meet a end point , we update the range [0,i-1] : -a[t];
*/
| [
"identifier.replace.add",
"literal.replace.remove",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 986,718 | 986,719 | u815544868 | cpp |
p03182 | // in the name of Allah
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define ll long long
#define double long double
#define sz(x) ((int)(x.size()))
#define fr first
#define se second
#define inf 1e18
#define max_n 2000002
#define mod 1000000007
ll add(ll a, ll b) {
a += b;
if (a >= mod)
return a - mod;
return a;
}
ll mul(ll a, ll b) {
a *= b;
if (a >= mod)
return a % mod;
return a;
}
ll power(ll a, ll b) {
ll p = 1;
while (b) {
if (b & 1)
p = mul(p, a);
a = mul(a, a);
b /= 2;
}
return p;
}
/*
const int _N = 1234567;
ll F[_N];
ll IF[_N];
void init() {
F[0] = 1;
for(int i=1; i<_N; i++) F[i] = mul(F[i-1], i);
IF[_N-1] = power(F[_N-1], mod-2);
for(int i=_N-2; i>=0; i--) IF[i] = mul(IF[i+1], i+1);
}
ll ncr(ll x, ll y) {
if(y > x || y < 0) return 0;
return mul(F[x], mul(IF[x-y], IF[y]));
}
/**/
/*
class mxLazySegTree {
public:
int sz;
vector <ll> tree, lazy;
mxLazySegTree(int _sz) {
sz = _sz;
tree.assign(sz*4, 0);
lazy.assign(sz*4, 0);
}
// update
void update(int p, int L, int R, int l, int r, ll val) {
if(R < l || r < L) return;
if(l <= L && R <= r) {
tree[p] += val;
lazy[2*p] += val;
lazy[2*p+1] += val;
return;
}
int M = (L+R)/2;
update(2*p, L, M, l, r, val);
update(2*p+1, M+1, R, l, r, val);
tree[p] = max(tree[2*p], tree[2*p+1]);
}
void update(int l, int r, ll val) {
update(1, 0, sz-1, l, r, val);
}
// query
ll query(int p, int L, int R, int l, int r) {
if(R < l || r < L) return -1e18;
if(lazy[p] != 0) {
tree[p] += lazy[p];
lazy[2*p] += lazy[p];
lazy[2*p+1] += lazy[p];
lazy[p] = 0;
}
if(l <= L && R <= r) return tree[p];
int M = (L+R)/2;
return max(query(2*p, L, M, l, r), query(2*p+1, M+1, R, l, r));
}
ll query(int l, int r) {
return query(1, 0, sz-1, l, r);
}
};
/**/
/*
class mxLazySegTree {
public:
int sz;
vector <ll> tree, lazy;
mxLazySegTree(int _sz) {
sz = _sz;
tree.assign(sz*4, 0);
lazy.assign(sz*4, 0);
}
// update
void update(int l, int r, ll val) {
for(int i=l; i<=r; i++) tree[i] += val;
}
// query
ll query(int l, int r) {
ll res = -inf;
for(int i=l; i<=r; i++) res = max(res, tree[i]);
return res;
}
};
/**/
class segment_tree {
private:
vector<ll> tree;
ll lazy[4 * max_n];
void build(int node, int start, int end) {
if (start == end)
tree[node] = A[start];
else {
int mid = (start + end) / 2;
build(2 * node, start, mid);
build(2 * node + 1, mid + 1, end);
tree[node] = max(tree[2 * node], tree[2 * node + 1]);
}
}
void updateRange(int node, int start, int end, int l, int r, ll val) {
if (lazy[node] != 0) {
tree[node] += lazy[node];
if (start != end) {
lazy[node * 2] += lazy[node];
lazy[node * 2 + 1] += lazy[node];
}
lazy[node] = 0;
}
if (start > end || start > r || end < l)
return;
if (start >= l && end <= r) {
tree[node] += val;
if (start != end) {
lazy[node * 2] += val;
lazy[node * 2 + 1] += val;
}
return;
}
int mid = (start + end) / 2;
updateRange(node * 2, start, mid, l, r, val);
updateRange(node * 2 + 1, mid + 1, end, l, r, val);
tree[node] = max(tree[node * 2], tree[node * 2 + 1]);
}
ll queryRange(int node, int start, int end, int l, int r) {
if (start > end || start > r || end < l)
return -inf;
if (lazy[node] != 0) {
tree[node] += lazy[node];
if (start != end) {
lazy[node * 2] += lazy[node];
lazy[node * 2 + 1] += lazy[node];
}
lazy[node] = 0;
}
if (start >= l && end <= r)
return tree[node];
int mid = (start + end) / 2;
ll p1 = queryRange(node * 2, start, mid, l, r);
ll p2 = queryRange(node * 2 + 1, mid + 1, end, l, r);
return max(p1, p2);
}
public:
int n;
vector<ll> A;
segment_tree(int sz) {
A.assign(sz, 0);
n = A.size();
tree.assign(4 * n, 0);
memset(lazy, 0, sizeof lazy);
build(1, 0, n - 1);
}
segment_tree(const vector<ll> &v) {
A = v;
n = A.size();
tree.assign(4 * n, 0);
memset(lazy, -1, sizeof lazy);
build(1, 0, n - 1);
}
ll query(int l, int r) { return queryRange(1, 0, n - 1, l, r); }
void update(int l, int r, int val) { updateRange(1, 0, n - 1, l, r, val); }
};
int n, m;
ll a[max_n];
int l[max_n], r[max_n];
vector<int> s[max_n];
vector<int> e[max_n];
int main() {
// ll start = clock();
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> l[i] >> r[i] >> a[i];
s[l[i]].pb(i);
e[r[i]].pb(i);
}
ll res = 0, ans;
segment_tree st(n + 1);
for (int i = 1; i <= n; i++) {
for (int id : s[i])
st.update(0, i - 1, a[id]);
ans = st.query(0, i - 1);
res = max(res, ans);
st.update(i, i, ans);
for (int id : e[i])
st.update(0, l[id] - 1, -a[id]);
}
cout << res << endl;
// cerr << (clock() - start) / (CLOCKS_PER_SEC*1.0) << endl;
return 0;
} | // in the name of Allah
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define ll long long
#define double long double
#define sz(x) ((int)(x.size()))
#define fr first
#define se second
#define inf 1e18
#define max_n 200002
#define mod 1000000007
ll add(ll a, ll b) {
a += b;
if (a >= mod)
return a - mod;
return a;
}
ll mul(ll a, ll b) {
a *= b;
if (a >= mod)
return a % mod;
return a;
}
ll power(ll a, ll b) {
ll p = 1;
while (b) {
if (b & 1)
p = mul(p, a);
a = mul(a, a);
b /= 2;
}
return p;
}
/*
// a bit of NT
const int _N = 1234567;
ll F[_N];
ll IF[_N];
void init() {
F[0] = 1;
for(int i=1; i<_N; i++) F[i] = mul(F[i-1], i);
IF[_N-1] = power(F[_N-1], mod-2);
for(int i=_N-2; i>=0; i--) IF[i] = mul(IF[i+1], i+1);
}
ll ncr(ll x, ll y) {
if(y > x || y < 0) return 0;
return mul(F[x], mul(IF[x-y], IF[y]));
}
/**/
class mxLazySegTree {
public:
int sz;
vector<ll> tree, lazy;
mxLazySegTree(int _sz) {
sz = _sz;
tree.assign(sz * 4, 0);
lazy.assign(sz * 4, 0);
}
// update
void update(int p, int L, int R, int l, int r, ll val) {
if (lazy[p] != 0) {
tree[p] += lazy[p];
if (L != R) {
lazy[2 * p] += lazy[p];
lazy[2 * p + 1] += lazy[p];
}
lazy[p] = 0;
}
if (R < l || r < L)
return;
if (l <= L && R <= r) {
tree[p] += val;
if (L != R) {
lazy[2 * p] += val;
lazy[2 * p + 1] += val;
}
return;
}
int M = (L + R) / 2;
update(2 * p, L, M, l, r, val);
update(2 * p + 1, M + 1, R, l, r, val);
tree[p] = max(tree[2 * p], tree[2 * p + 1]);
}
void update(int l, int r, ll val) { update(1, 0, sz - 1, l, r, val); }
// query
ll query(int p, int L, int R, int l, int r) {
if (R < l || r < L)
return -1e18;
if (lazy[p] != 0) {
tree[p] += lazy[p];
if (L != R) {
lazy[2 * p] += lazy[p];
lazy[2 * p + 1] += lazy[p];
}
lazy[p] = 0;
}
if (l <= L && R <= r)
return tree[p];
int M = (L + R) / 2;
return max(query(2 * p, L, M, l, r), query(2 * p + 1, M + 1, R, l, r));
}
ll query(int l, int r) { return query(1, 0, sz - 1, l, r); }
};
int n, m;
ll a[max_n];
int l[max_n], r[max_n];
vector<int> s[max_n];
vector<int> e[max_n];
int main() {
// ll start = clock();
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> l[i] >> r[i] >> a[i];
s[l[i]].pb(i);
e[r[i]].pb(i);
}
ll res = 0, ans;
mxLazySegTree st(n + 1);
for (int i = 1; i <= n; i++) {
for (int id : s[i])
st.update(0, i - 1, a[id]);
ans = st.query(0, i - 1);
res = max(res, ans);
st.update(i, i, ans);
for (int id : e[i])
st.update(0, l[id] - 1, -a[id]);
}
cout << res << endl;
// cerr << (clock() - start) / (CLOCKS_PER_SEC*1.0) << endl;
return 0;
} | [
"preprocessor.define.value.change",
"literal.integer.change"
] | 986,733 | 986,734 | u812771098 | cpp |
p03182 | // in the name of Allah
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define ll long long
#define double long double
#define sz(x) ((int)(x.size()))
#define fr first
#define se second
#define inf 1e9
#define max_n 200002
#define mod 1000000007
ll add(ll a, ll b) {
a += b;
if (a >= mod)
return a - mod;
return a;
}
ll mul(ll a, ll b) {
a *= b;
if (a >= mod)
return a % mod;
return a;
}
ll power(ll a, ll b) {
ll p = 1;
while (b) {
if (b & 1)
p = mul(p, a);
a = mul(a, a);
b /= 2;
}
return p;
}
/*
const int _N = 1234567;
ll F[_N];
ll IF[_N];
void init() {
F[0] = 1;
for(int i=1; i<_N; i++) F[i] = mul(F[i-1], i);
IF[_N-1] = power(F[_N-1], mod-2);
for(int i=_N-2; i>=0; i--) IF[i] = mul(IF[i+1], i+1);
}
ll ncr(ll x, ll y) {
if(y > x || y < 0) return 0;
return mul(F[x], mul(IF[x-y], IF[y]));
}
/**/
class mxLazySegTree {
public:
int sz;
vector<ll> tree, lazy;
mxLazySegTree(int _sz) {
sz = _sz;
tree.assign(sz * 4, 0);
lazy.assign(sz * 4, 0);
}
// update
void update(int p, int L, int R, int l, int r, ll val) {
if (R < l || r < L)
return;
if (l <= L && R <= r) {
tree[p] += val;
lazy[2 * p] += val;
lazy[2 * p + 1] += val;
return;
}
int M = (L + R) / 2;
update(2 * p, L, M, l, r, val);
update(2 * p + 1, M + 1, R, l, r, val);
tree[p] = max(tree[2 * p], tree[2 * p + 1]);
}
void update(int l, int r, ll val) { update(1, 0, sz - 1, l, r, val); }
// query
ll query(int p, int L, int R, int l, int r) {
if (R < l || r < L)
return -1e18;
if (lazy[p] != 0) {
tree[p] += lazy[p];
lazy[2 * p] += lazy[p];
lazy[2 * p + 1] += lazy[p];
lazy[p] = 0;
}
if (l <= L && R <= r)
return tree[p];
int M = (L + R) / 2;
return max(query(2 * p, L, M, l, r), query(2 * p + 1, M + 1, R, l, r));
}
ll query(int l, int r) { return query(1, 0, sz - 1, l, r); }
};
int n, m;
ll a[max_n];
int l[max_n], r[max_n];
vector<int> s[max_n];
vector<int> e[max_n];
int main() {
// ll start = clock();
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> l[i] >> r[i] >> a[i];
s[l[i]].pb(i);
e[r[i]].pb(i);
}
ll res = 0, ans;
mxLazySegTree st(n + 1);
for (int i = 1; i <= n; i++) {
for (int id : s[i])
st.update(0, i - 1, a[id]);
ans = st.query(0, i - 1);
res = max(res, ans);
st.update(i, i, ans);
for (int id : e[i])
st.update(0, l[id] - 1, -a[id]);
}
cout << res << endl;
// cerr << (clock() - start) / (CLOCKS_PER_SEC*1.0) << endl;
return 0;
} | // in the name of Allah
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define ll long long
#define double long double
#define sz(x) ((int)(x.size()))
#define fr first
#define se second
#define inf 1e18
#define max_n 200002
#define mod 1000000007
ll add(ll a, ll b) {
a += b;
if (a >= mod)
return a - mod;
return a;
}
ll mul(ll a, ll b) {
a *= b;
if (a >= mod)
return a % mod;
return a;
}
ll power(ll a, ll b) {
ll p = 1;
while (b) {
if (b & 1)
p = mul(p, a);
a = mul(a, a);
b /= 2;
}
return p;
}
/*
// a bit of NT
const int _N = 1234567;
ll F[_N];
ll IF[_N];
void init() {
F[0] = 1;
for(int i=1; i<_N; i++) F[i] = mul(F[i-1], i);
IF[_N-1] = power(F[_N-1], mod-2);
for(int i=_N-2; i>=0; i--) IF[i] = mul(IF[i+1], i+1);
}
ll ncr(ll x, ll y) {
if(y > x || y < 0) return 0;
return mul(F[x], mul(IF[x-y], IF[y]));
}
/**/
class mxLazySegTree {
public:
int sz;
vector<ll> tree, lazy;
mxLazySegTree(int _sz) {
sz = _sz;
tree.assign(sz * 4, 0);
lazy.assign(sz * 4, 0);
}
// update
void update(int p, int L, int R, int l, int r, ll val) {
if (lazy[p] != 0) {
tree[p] += lazy[p];
if (L != R) {
lazy[2 * p] += lazy[p];
lazy[2 * p + 1] += lazy[p];
}
lazy[p] = 0;
}
if (R < l || r < L)
return;
if (l <= L && R <= r) {
tree[p] += val;
if (L != R) {
lazy[2 * p] += val;
lazy[2 * p + 1] += val;
}
return;
}
int M = (L + R) / 2;
update(2 * p, L, M, l, r, val);
update(2 * p + 1, M + 1, R, l, r, val);
tree[p] = max(tree[2 * p], tree[2 * p + 1]);
}
void update(int l, int r, ll val) { update(1, 0, sz - 1, l, r, val); }
// query
ll query(int p, int L, int R, int l, int r) {
if (R < l || r < L)
return -1e18;
if (lazy[p] != 0) {
tree[p] += lazy[p];
if (L != R) {
lazy[2 * p] += lazy[p];
lazy[2 * p + 1] += lazy[p];
}
lazy[p] = 0;
}
if (l <= L && R <= r)
return tree[p];
int M = (L + R) / 2;
return max(query(2 * p, L, M, l, r), query(2 * p + 1, M + 1, R, l, r));
}
ll query(int l, int r) { return query(1, 0, sz - 1, l, r); }
};
int n, m;
ll a[max_n];
int l[max_n], r[max_n];
vector<int> s[max_n];
vector<int> e[max_n];
int main() {
// ll start = clock();
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> l[i] >> r[i] >> a[i];
s[l[i]].pb(i);
e[r[i]].pb(i);
}
ll res = 0, ans;
mxLazySegTree st(n + 1);
for (int i = 1; i <= n; i++) {
for (int id : s[i])
st.update(0, i - 1, a[id]);
ans = st.query(0, i - 1);
res = max(res, ans);
st.update(i, i, ans);
for (int id : e[i])
st.update(0, l[id] - 1, -a[id]);
}
cout << res << endl;
// cerr << (clock() - start) / (CLOCKS_PER_SEC*1.0) << endl;
return 0;
} | [
"preprocessor.define.value.change",
"literal.float.change"
] | 986,735 | 986,734 | u812771098 | cpp |
p03182 | // in the name of Allah
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define ll long long
#define double long double
#define sz(x) ((int)(x.size()))
#define fr first
#define se second
#define inf 1e18
#define max_n 2000002
#define mod 1000000007
ll add(ll a, ll b) {
a += b;
if (a >= mod)
return a - mod;
return a;
}
ll mul(ll a, ll b) {
a *= b;
if (a >= mod)
return a % mod;
return a;
}
ll power(ll a, ll b) {
ll p = 1;
while (b) {
if (b & 1)
p = mul(p, a);
a = mul(a, a);
b /= 2;
}
return p;
}
/*
const int _N = 1234567;
ll F[_N];
ll IF[_N];
void init() {
F[0] = 1;
for(int i=1; i<_N; i++) F[i] = mul(F[i-1], i);
IF[_N-1] = power(F[_N-1], mod-2);
for(int i=_N-2; i>=0; i--) IF[i] = mul(IF[i+1], i+1);
}
ll ncr(ll x, ll y) {
if(y > x || y < 0) return 0;
return mul(F[x], mul(IF[x-y], IF[y]));
}
/**/
/*
class mxLazySegTree {
public:
int sz;
vector <ll> tree, lazy;
mxLazySegTree(int _sz) {
sz = _sz;
tree.assign(sz*4, 0);
lazy.assign(sz*4, 0);
}
// update
void update(int p, int L, int R, int l, int r, ll val) {
if(R < l || r < L) return;
if(l <= L && R <= r) {
tree[p] += val;
lazy[2*p] += val;
lazy[2*p+1] += val;
return;
}
int M = (L+R)/2;
update(2*p, L, M, l, r, val);
update(2*p+1, M+1, R, l, r, val);
tree[p] = max(tree[2*p], tree[2*p+1]);
}
void update(int l, int r, ll val) {
update(1, 0, sz-1, l, r, val);
}
// query
ll query(int p, int L, int R, int l, int r) {
if(R < l || r < L) return -1e18;
if(lazy[p] != 0) {
tree[p] += lazy[p];
lazy[2*p] += lazy[p];
lazy[2*p+1] += lazy[p];
lazy[p] = 0;
}
if(l <= L && R <= r) return tree[p];
int M = (L+R)/2;
return max(query(2*p, L, M, l, r), query(2*p+1, M+1, R, l, r));
}
ll query(int l, int r) {
return query(1, 0, sz-1, l, r);
}
};
/**/
/*
class mxLazySegTree {
public:
int sz;
vector <ll> tree, lazy;
mxLazySegTree(int _sz) {
sz = _sz;
tree.assign(sz*4, 0);
lazy.assign(sz*4, 0);
}
// update
void update(int l, int r, ll val) {
for(int i=l; i<=r; i++) tree[i] += val;
}
// query
ll query(int l, int r) {
ll res = -inf;
for(int i=l; i<=r; i++) res = max(res, tree[i]);
return res;
}
};
/**/
class segment_tree {
private:
vector<ll> tree;
ll lazy[4 * max_n];
void build(int node, int start, int end) {
if (start == end)
tree[node] = A[start];
else {
int mid = (start + end) / 2;
build(2 * node, start, mid);
build(2 * node + 1, mid + 1, end);
tree[node] = max(tree[2 * node], tree[2 * node + 1]);
}
}
void updateRange(int node, int start, int end, int l, int r, ll val) {
if (lazy[node] != 0) {
tree[node] += lazy[node];
if (start != end) {
lazy[node * 2] += lazy[node];
lazy[node * 2 + 1] += lazy[node];
}
lazy[node] = 0;
}
if (start > end || start > r || end < l)
return;
if (start >= l && end <= r) {
tree[node] += val;
if (start != end) {
lazy[node * 2] += val;
lazy[node * 2 + 1] += val;
}
return;
}
int mid = (start + end) / 2;
updateRange(node * 2, start, mid, l, r, val);
updateRange(node * 2 + 1, mid + 1, end, l, r, val);
tree[node] = max(tree[node * 2], tree[node * 2 + 1]);
}
ll queryRange(int node, int start, int end, int l, int r) {
if (start > end || start > r || end < l)
return -inf;
if (lazy[node] != 0) {
tree[node] += lazy[node];
if (start != end) {
lazy[node * 2] += lazy[node];
lazy[node * 2 + 1] += lazy[node];
}
lazy[node] = 0;
}
if (start >= l && end <= r)
return tree[node];
int mid = (start + end) / 2;
ll p1 = queryRange(node * 2, start, mid, l, r);
ll p2 = queryRange(node * 2 + 1, mid + 1, end, l, r);
return max(p1, p2);
}
public:
int n;
vector<ll> A;
segment_tree(int sz) {
A.assign(sz, 0);
n = A.size();
tree.assign(4 * n, 0);
memset(lazy, 0, sizeof lazy);
build(1, 0, n - 1);
}
segment_tree(const vector<ll> &v) {
A = v;
n = A.size();
tree.assign(4 * n, 0);
memset(lazy, -1, sizeof lazy);
build(1, 0, n - 1);
}
ll query(int l, int r) { return queryRange(1, 0, n - 1, l, r); }
void update(int l, int r, int val) { updateRange(1, 0, n - 1, l, r, val); }
};
int n, m;
ll a[max_n];
int l[max_n], r[max_n];
vector<int> s[max_n];
vector<int> e[max_n];
int main() {
// ll start = clock();
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> l[i] >> r[i] >> a[i];
s[l[i]].pb(i);
e[r[i]].pb(i);
}
ll res = 0, ans;
segment_tree st(n + 1);
for (int i = 1; i <= n; i++) {
for (int id : s[i])
st.update(0, i - 1, a[id]);
ans = st.query(0, i - 1);
res = max(res, ans);
st.update(i, i, ans);
for (int id : e[i])
st.update(0, l[id] - 1, -a[id]);
}
cout << res << endl;
// cerr << (clock() - start) / (CLOCKS_PER_SEC*1.0) << endl;
return 0;
} | // in the name of Allah
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define ll long long
#define double long double
#define sz(x) ((int)(x.size()))
#define fr first
#define se second
#define inf 1e18
#define max_n 200002
#define mod 1000000007
ll add(ll a, ll b) {
a += b;
if (a >= mod)
return a - mod;
return a;
}
ll mul(ll a, ll b) {
a *= b;
if (a >= mod)
return a % mod;
return a;
}
ll power(ll a, ll b) {
ll p = 1;
while (b) {
if (b & 1)
p = mul(p, a);
a = mul(a, a);
b /= 2;
}
return p;
}
/*
// a bit of NT
const int _N = 1234567;
ll F[_N];
ll IF[_N];
void init() {
F[0] = 1;
for(int i=1; i<_N; i++) F[i] = mul(F[i-1], i);
IF[_N-1] = power(F[_N-1], mod-2);
for(int i=_N-2; i>=0; i--) IF[i] = mul(IF[i+1], i+1);
}
ll ncr(ll x, ll y) {
if(y > x || y < 0) return 0;
return mul(F[x], mul(IF[x-y], IF[y]));
}
/**/
class mxLazySegTree {
public:
int sz;
vector<ll> tree, lazy;
mxLazySegTree(int _sz) {
sz = _sz;
tree.assign(sz * 10, 0);
lazy.assign(sz * 10, 0);
}
// update
void update(int p, int L, int R, int l, int r, ll val) {
if (lazy[p] != 0) {
tree[p] += lazy[p];
// if(L != R) {
lazy[2 * p] += lazy[p];
lazy[2 * p + 1] += lazy[p];
// }
lazy[p] = 0;
}
if (R < l || r < L)
return;
if (l <= L && R <= r) {
tree[p] += val;
// if(L != R) {
lazy[2 * p] += val;
lazy[2 * p + 1] += val;
// }
return;
}
int M = (L + R) / 2;
update(2 * p, L, M, l, r, val);
update(2 * p + 1, M + 1, R, l, r, val);
tree[p] = max(tree[2 * p], tree[2 * p + 1]);
}
void update(int l, int r, ll val) { update(1, 0, sz - 1, l, r, val); }
// query
ll query(int p, int L, int R, int l, int r) {
if (R < l || r < L)
return -1e18;
if (lazy[p] != 0) {
tree[p] += lazy[p];
// if(L != R) {
lazy[2 * p] += lazy[p];
lazy[2 * p + 1] += lazy[p];
// }
lazy[p] = 0;
}
if (l <= L && R <= r)
return tree[p];
int M = (L + R) / 2;
return max(query(2 * p, L, M, l, r), query(2 * p + 1, M + 1, R, l, r));
}
ll query(int l, int r) { return query(1, 0, sz - 1, l, r); }
};
int n, m;
ll a[max_n];
int l[max_n], r[max_n];
vector<int> s[max_n];
vector<int> e[max_n];
int main() {
// ll start = clock();
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> l[i] >> r[i] >> a[i];
s[l[i]].pb(i);
e[r[i]].pb(i);
}
ll res = 0, ans;
mxLazySegTree st(n + 1);
for (int i = 1; i <= n; i++) {
for (int id : s[i])
st.update(0, i - 1, a[id]);
ans = st.query(0, i - 1);
res = max(res, ans);
st.update(i, i, ans);
for (int id : e[i])
st.update(0, l[id] - 1, -a[id]);
}
cout << res << endl;
// cerr << (clock() - start) / (CLOCKS_PER_SEC*1.0) << endl;
return 0;
} | [
"preprocessor.define.value.change",
"literal.integer.change"
] | 986,733 | 986,737 | u812771098 | cpp |
p03182 | // in the name of Allah
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define ll long long
#define double long double
#define sz(x) ((int)(x.size()))
#define fr first
#define se second
#define inf 1e9
#define max_n 200002
#define mod 1000000007
ll add(ll a, ll b) {
a += b;
if (a >= mod)
return a - mod;
return a;
}
ll mul(ll a, ll b) {
a *= b;
if (a >= mod)
return a % mod;
return a;
}
ll power(ll a, ll b) {
ll p = 1;
while (b) {
if (b & 1)
p = mul(p, a);
a = mul(a, a);
b /= 2;
}
return p;
}
/*
const int _N = 1234567;
ll F[_N];
ll IF[_N];
void init() {
F[0] = 1;
for(int i=1; i<_N; i++) F[i] = mul(F[i-1], i);
IF[_N-1] = power(F[_N-1], mod-2);
for(int i=_N-2; i>=0; i--) IF[i] = mul(IF[i+1], i+1);
}
ll ncr(ll x, ll y) {
if(y > x || y < 0) return 0;
return mul(F[x], mul(IF[x-y], IF[y]));
}
/**/
class mxLazySegTree {
public:
int sz;
vector<ll> tree, lazy;
mxLazySegTree(int _sz) {
sz = _sz;
tree.assign(sz * 4, 0);
lazy.assign(sz * 4, 0);
}
// update
void update(int p, int L, int R, int l, int r, ll val) {
if (R < l || r < L)
return;
if (l <= L && R <= r) {
tree[p] += val;
lazy[2 * p] += val;
lazy[2 * p + 1] += val;
return;
}
int M = (L + R) / 2;
update(2 * p, L, M, l, r, val);
update(2 * p + 1, M + 1, R, l, r, val);
tree[p] = max(tree[2 * p], tree[2 * p + 1]);
}
void update(int l, int r, ll val) { update(1, 0, sz - 1, l, r, val); }
// query
ll query(int p, int L, int R, int l, int r) {
if (R < l || r < L)
return -1e18;
if (lazy[p] != 0) {
tree[p] += lazy[p];
lazy[2 * p] += lazy[p];
lazy[2 * p + 1] += lazy[p];
lazy[p] = 0;
}
if (l <= L && R <= r)
return tree[p];
int M = (L + R) / 2;
return max(query(2 * p, L, M, l, r), query(2 * p + 1, M + 1, R, l, r));
}
ll query(int l, int r) { return query(1, 0, sz - 1, l, r); }
};
int n, m;
ll a[max_n];
int l[max_n], r[max_n];
vector<int> s[max_n];
vector<int> e[max_n];
int main() {
// ll start = clock();
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> l[i] >> r[i] >> a[i];
s[l[i]].pb(i);
e[r[i]].pb(i);
}
ll res = 0, ans;
mxLazySegTree st(n + 1);
for (int i = 1; i <= n; i++) {
for (int id : s[i])
st.update(0, i - 1, a[id]);
ans = st.query(0, i - 1);
res = max(res, ans);
st.update(i, i, ans);
for (int id : e[i])
st.update(0, l[id] - 1, -a[id]);
}
cout << res << endl;
// cerr << (clock() - start) / (CLOCKS_PER_SEC*1.0) << endl;
return 0;
} | // in the name of Allah
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define ll long long
#define double long double
#define sz(x) ((int)(x.size()))
#define fr first
#define se second
#define inf 1e18
#define max_n 200002
#define mod 1000000007
ll add(ll a, ll b) {
a += b;
if (a >= mod)
return a - mod;
return a;
}
ll mul(ll a, ll b) {
a *= b;
if (a >= mod)
return a % mod;
return a;
}
ll power(ll a, ll b) {
ll p = 1;
while (b) {
if (b & 1)
p = mul(p, a);
a = mul(a, a);
b /= 2;
}
return p;
}
/*
// a bit of NT
const int _N = 1234567;
ll F[_N];
ll IF[_N];
void init() {
F[0] = 1;
for(int i=1; i<_N; i++) F[i] = mul(F[i-1], i);
IF[_N-1] = power(F[_N-1], mod-2);
for(int i=_N-2; i>=0; i--) IF[i] = mul(IF[i+1], i+1);
}
ll ncr(ll x, ll y) {
if(y > x || y < 0) return 0;
return mul(F[x], mul(IF[x-y], IF[y]));
}
/**/
class mxLazySegTree {
public:
int sz;
vector<ll> tree, lazy;
mxLazySegTree(int _sz) {
sz = _sz;
tree.assign(sz * 10, 0);
lazy.assign(sz * 10, 0);
}
// update
void update(int p, int L, int R, int l, int r, ll val) {
if (lazy[p] != 0) {
tree[p] += lazy[p];
// if(L != R) {
lazy[2 * p] += lazy[p];
lazy[2 * p + 1] += lazy[p];
// }
lazy[p] = 0;
}
if (R < l || r < L)
return;
if (l <= L && R <= r) {
tree[p] += val;
// if(L != R) {
lazy[2 * p] += val;
lazy[2 * p + 1] += val;
// }
return;
}
int M = (L + R) / 2;
update(2 * p, L, M, l, r, val);
update(2 * p + 1, M + 1, R, l, r, val);
tree[p] = max(tree[2 * p], tree[2 * p + 1]);
}
void update(int l, int r, ll val) { update(1, 0, sz - 1, l, r, val); }
// query
ll query(int p, int L, int R, int l, int r) {
if (R < l || r < L)
return -1e18;
if (lazy[p] != 0) {
tree[p] += lazy[p];
// if(L != R) {
lazy[2 * p] += lazy[p];
lazy[2 * p + 1] += lazy[p];
// }
lazy[p] = 0;
}
if (l <= L && R <= r)
return tree[p];
int M = (L + R) / 2;
return max(query(2 * p, L, M, l, r), query(2 * p + 1, M + 1, R, l, r));
}
ll query(int l, int r) { return query(1, 0, sz - 1, l, r); }
};
int n, m;
ll a[max_n];
int l[max_n], r[max_n];
vector<int> s[max_n];
vector<int> e[max_n];
int main() {
// ll start = clock();
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> l[i] >> r[i] >> a[i];
s[l[i]].pb(i);
e[r[i]].pb(i);
}
ll res = 0, ans;
mxLazySegTree st(n + 1);
for (int i = 1; i <= n; i++) {
for (int id : s[i])
st.update(0, i - 1, a[id]);
ans = st.query(0, i - 1);
res = max(res, ans);
st.update(i, i, ans);
for (int id : e[i])
st.update(0, l[id] - 1, -a[id]);
}
cout << res << endl;
// cerr << (clock() - start) / (CLOCKS_PER_SEC*1.0) << endl;
return 0;
} | [
"preprocessor.define.value.change",
"literal.float.change"
] | 986,735 | 986,737 | u812771098 | cpp |
p03182 | // in the name of Allah
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define ll long long
#define double long double
#define sz(x) ((int)(x.size()))
#define fr first
#define se second
#define inf 1e18
#define max_n 2000002
#define mod 1000000007
ll add(ll a, ll b) {
a += b;
if (a >= mod)
return a - mod;
return a;
}
ll mul(ll a, ll b) {
a *= b;
if (a >= mod)
return a % mod;
return a;
}
ll power(ll a, ll b) {
ll p = 1;
while (b) {
if (b & 1)
p = mul(p, a);
a = mul(a, a);
b /= 2;
}
return p;
}
/*
const int _N = 1234567;
ll F[_N];
ll IF[_N];
void init() {
F[0] = 1;
for(int i=1; i<_N; i++) F[i] = mul(F[i-1], i);
IF[_N-1] = power(F[_N-1], mod-2);
for(int i=_N-2; i>=0; i--) IF[i] = mul(IF[i+1], i+1);
}
ll ncr(ll x, ll y) {
if(y > x || y < 0) return 0;
return mul(F[x], mul(IF[x-y], IF[y]));
}
/**/
/*
class mxLazySegTree {
public:
int sz;
vector <ll> tree, lazy;
mxLazySegTree(int _sz) {
sz = _sz;
tree.assign(sz*4, 0);
lazy.assign(sz*4, 0);
}
// update
void update(int p, int L, int R, int l, int r, ll val) {
if(R < l || r < L) return;
if(l <= L && R <= r) {
tree[p] += val;
lazy[2*p] += val;
lazy[2*p+1] += val;
return;
}
int M = (L+R)/2;
update(2*p, L, M, l, r, val);
update(2*p+1, M+1, R, l, r, val);
tree[p] = max(tree[2*p], tree[2*p+1]);
}
void update(int l, int r, ll val) {
update(1, 0, sz-1, l, r, val);
}
// query
ll query(int p, int L, int R, int l, int r) {
if(R < l || r < L) return -1e18;
if(lazy[p] != 0) {
tree[p] += lazy[p];
lazy[2*p] += lazy[p];
lazy[2*p+1] += lazy[p];
lazy[p] = 0;
}
if(l <= L && R <= r) return tree[p];
int M = (L+R)/2;
return max(query(2*p, L, M, l, r), query(2*p+1, M+1, R, l, r));
}
ll query(int l, int r) {
return query(1, 0, sz-1, l, r);
}
};
/**/
/*
class mxLazySegTree {
public:
int sz;
vector <ll> tree, lazy;
mxLazySegTree(int _sz) {
sz = _sz;
tree.assign(sz*4, 0);
lazy.assign(sz*4, 0);
}
// update
void update(int l, int r, ll val) {
for(int i=l; i<=r; i++) tree[i] += val;
}
// query
ll query(int l, int r) {
ll res = -inf;
for(int i=l; i<=r; i++) res = max(res, tree[i]);
return res;
}
};
/**/
class segment_tree {
private:
vector<ll> tree;
ll lazy[4 * max_n];
void build(int node, int start, int end) {
if (start == end)
tree[node] = A[start];
else {
int mid = (start + end) / 2;
build(2 * node, start, mid);
build(2 * node + 1, mid + 1, end);
tree[node] = max(tree[2 * node], tree[2 * node + 1]);
}
}
void updateRange(int node, int start, int end, int l, int r, ll val) {
if (lazy[node] != 0) {
tree[node] += lazy[node];
if (start != end) {
lazy[node * 2] += lazy[node];
lazy[node * 2 + 1] += lazy[node];
}
lazy[node] = 0;
}
if (start > end || start > r || end < l)
return;
if (start >= l && end <= r) {
tree[node] += val;
if (start != end) {
lazy[node * 2] += val;
lazy[node * 2 + 1] += val;
}
return;
}
int mid = (start + end) / 2;
updateRange(node * 2, start, mid, l, r, val);
updateRange(node * 2 + 1, mid + 1, end, l, r, val);
tree[node] = max(tree[node * 2], tree[node * 2 + 1]);
}
ll queryRange(int node, int start, int end, int l, int r) {
if (start > end || start > r || end < l)
return -inf;
if (lazy[node] != 0) {
tree[node] += lazy[node];
if (start != end) {
lazy[node * 2] += lazy[node];
lazy[node * 2 + 1] += lazy[node];
}
lazy[node] = 0;
}
if (start >= l && end <= r)
return tree[node];
int mid = (start + end) / 2;
ll p1 = queryRange(node * 2, start, mid, l, r);
ll p2 = queryRange(node * 2 + 1, mid + 1, end, l, r);
return max(p1, p2);
}
public:
int n;
vector<ll> A;
segment_tree(int sz) {
A.assign(sz, 0);
n = A.size();
tree.assign(4 * n, 0);
memset(lazy, 0, sizeof lazy);
build(1, 0, n - 1);
}
segment_tree(const vector<ll> &v) {
A = v;
n = A.size();
tree.assign(4 * n, 0);
memset(lazy, -1, sizeof lazy);
build(1, 0, n - 1);
}
ll query(int l, int r) { return queryRange(1, 0, n - 1, l, r); }
void update(int l, int r, int val) { updateRange(1, 0, n - 1, l, r, val); }
};
int n, m;
ll a[max_n];
int l[max_n], r[max_n];
vector<int> s[max_n];
vector<int> e[max_n];
int main() {
// ll start = clock();
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> l[i] >> r[i] >> a[i];
s[l[i]].pb(i);
e[r[i]].pb(i);
}
ll res = 0, ans;
segment_tree st(n + 1);
for (int i = 1; i <= n; i++) {
for (int id : s[i])
st.update(0, i - 1, a[id]);
ans = st.query(0, i - 1);
res = max(res, ans);
st.update(i, i, ans);
for (int id : e[i])
st.update(0, l[id] - 1, -a[id]);
}
cout << res << endl;
// cerr << (clock() - start) / (CLOCKS_PER_SEC*1.0) << endl;
return 0;
} | // in the name of Allah
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define ll long long
#define double long double
#define sz(x) ((int)(x.size()))
#define fr first
#define se second
#define inf 1e18
#define max_n 200002
#define mod 1000000007
ll add(ll a, ll b) {
a += b;
if (a >= mod)
return a - mod;
return a;
}
ll mul(ll a, ll b) {
a *= b;
if (a >= mod)
return a % mod;
return a;
}
ll power(ll a, ll b) {
ll p = 1;
while (b) {
if (b & 1)
p = mul(p, a);
a = mul(a, a);
b /= 2;
}
return p;
}
/*
const int _N = 1234567;
ll F[_N];
ll IF[_N];
void init() {
F[0] = 1;
for(int i=1; i<_N; i++) F[i] = mul(F[i-1], i);
IF[_N-1] = power(F[_N-1], mod-2);
for(int i=_N-2; i>=0; i--) IF[i] = mul(IF[i+1], i+1);
}
ll ncr(ll x, ll y) {
if(y > x || y < 0) return 0;
return mul(F[x], mul(IF[x-y], IF[y]));
}
/**/
class mxLazySegTree {
public:
int sz;
vector<ll> tree, lazy;
mxLazySegTree(int _sz) {
sz = _sz;
tree.assign(sz * 4, 0);
lazy.assign(sz * 4, 0);
}
// update
void update(int p, int L, int R, int l, int r, ll val) {
if (lazy[p] != 0) {
tree[p] += lazy[p];
if (L != R) {
lazy[2 * p] += lazy[p];
lazy[2 * p + 1] += lazy[p];
}
lazy[p] = 0;
}
if (R < l || r < L)
return; // R < L
if (l <= L && R <= r) {
tree[p] += val;
if (L != R) {
lazy[2 * p] += val;
lazy[2 * p + 1] += val;
}
return;
}
int M = (L + R) / 2;
update(2 * p, L, M, l, r, val);
update(2 * p + 1, M + 1, R, l, r, val);
tree[p] = max(tree[2 * p], tree[2 * p + 1]);
}
void update(int l, int r, ll val) { update(1, 0, sz - 1, l, r, val); }
// query
ll query(int p, int L, int R, int l, int r) {
if (R < l || r < L)
return -1e18; // L > R
if (lazy[p] != 0) {
tree[p] += lazy[p];
if (L != R) {
lazy[2 * p] += lazy[p];
lazy[2 * p + 1] += lazy[p];
}
lazy[p] = 0;
}
if (l <= L && R <= r)
return tree[p];
int M = (L + R) / 2;
return max(query(2 * p, L, M, l, r), query(2 * p + 1, M + 1, R, l, r));
}
ll query(int l, int r) { return query(1, 0, sz - 1, l, r); }
};
int n, m;
ll a[max_n];
int l[max_n], r[max_n];
vector<int> s[max_n];
vector<int> e[max_n];
int main() {
// ll start = clock();
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> l[i] >> r[i] >> a[i];
s[l[i]].pb(i);
e[r[i]].pb(i);
}
ll res = 0, ans;
mxLazySegTree st(n + 1);
for (int i = 1; i <= n; i++) {
for (int id : s[i])
st.update(0, i - 1, a[id]);
ans = st.query(0, i - 1);
res = max(res, ans);
st.update(i, i, ans);
for (int id : e[i])
st.update(0, l[id] - 1, -a[id]);
}
cout << res << endl;
// cerr << (clock() - start) / (CLOCKS_PER_SEC*1.0) << endl;
return 0;
} | [
"preprocessor.define.value.change",
"literal.integer.change"
] | 986,733 | 986,738 | u812771098 | cpp |
p03182 | // in the name of Allah
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define ll long long
#define double long double
#define sz(x) ((int)(x.size()))
#define fr first
#define se second
#define inf 1e9
#define max_n 200002
#define mod 1000000007
ll add(ll a, ll b) {
a += b;
if (a >= mod)
return a - mod;
return a;
}
ll mul(ll a, ll b) {
a *= b;
if (a >= mod)
return a % mod;
return a;
}
ll power(ll a, ll b) {
ll p = 1;
while (b) {
if (b & 1)
p = mul(p, a);
a = mul(a, a);
b /= 2;
}
return p;
}
/*
const int _N = 1234567;
ll F[_N];
ll IF[_N];
void init() {
F[0] = 1;
for(int i=1; i<_N; i++) F[i] = mul(F[i-1], i);
IF[_N-1] = power(F[_N-1], mod-2);
for(int i=_N-2; i>=0; i--) IF[i] = mul(IF[i+1], i+1);
}
ll ncr(ll x, ll y) {
if(y > x || y < 0) return 0;
return mul(F[x], mul(IF[x-y], IF[y]));
}
/**/
class mxLazySegTree {
public:
int sz;
vector<ll> tree, lazy;
mxLazySegTree(int _sz) {
sz = _sz;
tree.assign(sz * 4, 0);
lazy.assign(sz * 4, 0);
}
// update
void update(int p, int L, int R, int l, int r, ll val) {
if (R < l || r < L)
return;
if (l <= L && R <= r) {
tree[p] += val;
lazy[2 * p] += val;
lazy[2 * p + 1] += val;
return;
}
int M = (L + R) / 2;
update(2 * p, L, M, l, r, val);
update(2 * p + 1, M + 1, R, l, r, val);
tree[p] = max(tree[2 * p], tree[2 * p + 1]);
}
void update(int l, int r, ll val) { update(1, 0, sz - 1, l, r, val); }
// query
ll query(int p, int L, int R, int l, int r) {
if (R < l || r < L)
return -1e18;
if (lazy[p] != 0) {
tree[p] += lazy[p];
lazy[2 * p] += lazy[p];
lazy[2 * p + 1] += lazy[p];
lazy[p] = 0;
}
if (l <= L && R <= r)
return tree[p];
int M = (L + R) / 2;
return max(query(2 * p, L, M, l, r), query(2 * p + 1, M + 1, R, l, r));
}
ll query(int l, int r) { return query(1, 0, sz - 1, l, r); }
};
int n, m;
ll a[max_n];
int l[max_n], r[max_n];
vector<int> s[max_n];
vector<int> e[max_n];
int main() {
// ll start = clock();
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> l[i] >> r[i] >> a[i];
s[l[i]].pb(i);
e[r[i]].pb(i);
}
ll res = 0, ans;
mxLazySegTree st(n + 1);
for (int i = 1; i <= n; i++) {
for (int id : s[i])
st.update(0, i - 1, a[id]);
ans = st.query(0, i - 1);
res = max(res, ans);
st.update(i, i, ans);
for (int id : e[i])
st.update(0, l[id] - 1, -a[id]);
}
cout << res << endl;
// cerr << (clock() - start) / (CLOCKS_PER_SEC*1.0) << endl;
return 0;
} | // in the name of Allah
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define ll long long
#define double long double
#define sz(x) ((int)(x.size()))
#define fr first
#define se second
#define inf 1e18
#define max_n 200002
#define mod 1000000007
ll add(ll a, ll b) {
a += b;
if (a >= mod)
return a - mod;
return a;
}
ll mul(ll a, ll b) {
a *= b;
if (a >= mod)
return a % mod;
return a;
}
ll power(ll a, ll b) {
ll p = 1;
while (b) {
if (b & 1)
p = mul(p, a);
a = mul(a, a);
b /= 2;
}
return p;
}
/*
const int _N = 1234567;
ll F[_N];
ll IF[_N];
void init() {
F[0] = 1;
for(int i=1; i<_N; i++) F[i] = mul(F[i-1], i);
IF[_N-1] = power(F[_N-1], mod-2);
for(int i=_N-2; i>=0; i--) IF[i] = mul(IF[i+1], i+1);
}
ll ncr(ll x, ll y) {
if(y > x || y < 0) return 0;
return mul(F[x], mul(IF[x-y], IF[y]));
}
/**/
class mxLazySegTree {
public:
int sz;
vector<ll> tree, lazy;
mxLazySegTree(int _sz) {
sz = _sz;
tree.assign(sz * 4, 0);
lazy.assign(sz * 4, 0);
}
// update
void update(int p, int L, int R, int l, int r, ll val) {
if (lazy[p] != 0) {
tree[p] += lazy[p];
if (L != R) {
lazy[2 * p] += lazy[p];
lazy[2 * p + 1] += lazy[p];
}
lazy[p] = 0;
}
if (R < l || r < L)
return; // R < L
if (l <= L && R <= r) {
tree[p] += val;
if (L != R) {
lazy[2 * p] += val;
lazy[2 * p + 1] += val;
}
return;
}
int M = (L + R) / 2;
update(2 * p, L, M, l, r, val);
update(2 * p + 1, M + 1, R, l, r, val);
tree[p] = max(tree[2 * p], tree[2 * p + 1]);
}
void update(int l, int r, ll val) { update(1, 0, sz - 1, l, r, val); }
// query
ll query(int p, int L, int R, int l, int r) {
if (R < l || r < L)
return -1e18; // L > R
if (lazy[p] != 0) {
tree[p] += lazy[p];
if (L != R) {
lazy[2 * p] += lazy[p];
lazy[2 * p + 1] += lazy[p];
}
lazy[p] = 0;
}
if (l <= L && R <= r)
return tree[p];
int M = (L + R) / 2;
return max(query(2 * p, L, M, l, r), query(2 * p + 1, M + 1, R, l, r));
}
ll query(int l, int r) { return query(1, 0, sz - 1, l, r); }
};
int n, m;
ll a[max_n];
int l[max_n], r[max_n];
vector<int> s[max_n];
vector<int> e[max_n];
int main() {
// ll start = clock();
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> l[i] >> r[i] >> a[i];
s[l[i]].pb(i);
e[r[i]].pb(i);
}
ll res = 0, ans;
mxLazySegTree st(n + 1);
for (int i = 1; i <= n; i++) {
for (int id : s[i])
st.update(0, i - 1, a[id]);
ans = st.query(0, i - 1);
res = max(res, ans);
st.update(i, i, ans);
for (int id : e[i])
st.update(0, l[id] - 1, -a[id]);
}
cout << res << endl;
// cerr << (clock() - start) / (CLOCKS_PER_SEC*1.0) << endl;
return 0;
} | [
"preprocessor.define.value.change",
"literal.float.change"
] | 986,735 | 986,738 | u812771098 | cpp |
p03182 | // in the name of Allah
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define ll long long
#define double long double
#define sz(x) ((int)(x.size()))
#define fr first
#define se second
#define inf 1e18
#define max_n 2000002
#define mod 1000000007
ll add(ll a, ll b) {
a += b;
if (a >= mod)
return a - mod;
return a;
}
ll mul(ll a, ll b) {
a *= b;
if (a >= mod)
return a % mod;
return a;
}
ll power(ll a, ll b) {
ll p = 1;
while (b) {
if (b & 1)
p = mul(p, a);
a = mul(a, a);
b /= 2;
}
return p;
}
/*
const int _N = 1234567;
ll F[_N];
ll IF[_N];
void init() {
F[0] = 1;
for(int i=1; i<_N; i++) F[i] = mul(F[i-1], i);
IF[_N-1] = power(F[_N-1], mod-2);
for(int i=_N-2; i>=0; i--) IF[i] = mul(IF[i+1], i+1);
}
ll ncr(ll x, ll y) {
if(y > x || y < 0) return 0;
return mul(F[x], mul(IF[x-y], IF[y]));
}
/**/
/*
class mxLazySegTree {
public:
int sz;
vector <ll> tree, lazy;
mxLazySegTree(int _sz) {
sz = _sz;
tree.assign(sz*4, 0);
lazy.assign(sz*4, 0);
}
// update
void update(int p, int L, int R, int l, int r, ll val) {
if(R < l || r < L) return;
if(l <= L && R <= r) {
tree[p] += val;
lazy[2*p] += val;
lazy[2*p+1] += val;
return;
}
int M = (L+R)/2;
update(2*p, L, M, l, r, val);
update(2*p+1, M+1, R, l, r, val);
tree[p] = max(tree[2*p], tree[2*p+1]);
}
void update(int l, int r, ll val) {
update(1, 0, sz-1, l, r, val);
}
// query
ll query(int p, int L, int R, int l, int r) {
if(R < l || r < L) return -1e18;
if(lazy[p] != 0) {
tree[p] += lazy[p];
lazy[2*p] += lazy[p];
lazy[2*p+1] += lazy[p];
lazy[p] = 0;
}
if(l <= L && R <= r) return tree[p];
int M = (L+R)/2;
return max(query(2*p, L, M, l, r), query(2*p+1, M+1, R, l, r));
}
ll query(int l, int r) {
return query(1, 0, sz-1, l, r);
}
};
/**/
/*
class mxLazySegTree {
public:
int sz;
vector <ll> tree, lazy;
mxLazySegTree(int _sz) {
sz = _sz;
tree.assign(sz*4, 0);
lazy.assign(sz*4, 0);
}
// update
void update(int l, int r, ll val) {
for(int i=l; i<=r; i++) tree[i] += val;
}
// query
ll query(int l, int r) {
ll res = -inf;
for(int i=l; i<=r; i++) res = max(res, tree[i]);
return res;
}
};
/**/
class segment_tree {
private:
vector<ll> tree;
ll lazy[4 * max_n];
void build(int node, int start, int end) {
if (start == end)
tree[node] = A[start];
else {
int mid = (start + end) / 2;
build(2 * node, start, mid);
build(2 * node + 1, mid + 1, end);
tree[node] = max(tree[2 * node], tree[2 * node + 1]);
}
}
void updateRange(int node, int start, int end, int l, int r, ll val) {
if (lazy[node] != 0) {
tree[node] += lazy[node];
if (start != end) {
lazy[node * 2] += lazy[node];
lazy[node * 2 + 1] += lazy[node];
}
lazy[node] = 0;
}
if (start > end || start > r || end < l)
return;
if (start >= l && end <= r) {
tree[node] += val;
if (start != end) {
lazy[node * 2] += val;
lazy[node * 2 + 1] += val;
}
return;
}
int mid = (start + end) / 2;
updateRange(node * 2, start, mid, l, r, val);
updateRange(node * 2 + 1, mid + 1, end, l, r, val);
tree[node] = max(tree[node * 2], tree[node * 2 + 1]);
}
ll queryRange(int node, int start, int end, int l, int r) {
if (start > end || start > r || end < l)
return -inf;
if (lazy[node] != 0) {
tree[node] += lazy[node];
if (start != end) {
lazy[node * 2] += lazy[node];
lazy[node * 2 + 1] += lazy[node];
}
lazy[node] = 0;
}
if (start >= l && end <= r)
return tree[node];
int mid = (start + end) / 2;
ll p1 = queryRange(node * 2, start, mid, l, r);
ll p2 = queryRange(node * 2 + 1, mid + 1, end, l, r);
return max(p1, p2);
}
public:
int n;
vector<ll> A;
segment_tree(int sz) {
A.assign(sz, 0);
n = A.size();
tree.assign(4 * n, 0);
memset(lazy, 0, sizeof lazy);
build(1, 0, n - 1);
}
segment_tree(const vector<ll> &v) {
A = v;
n = A.size();
tree.assign(4 * n, 0);
memset(lazy, -1, sizeof lazy);
build(1, 0, n - 1);
}
ll query(int l, int r) { return queryRange(1, 0, n - 1, l, r); }
void update(int l, int r, int val) { updateRange(1, 0, n - 1, l, r, val); }
};
int n, m;
ll a[max_n];
int l[max_n], r[max_n];
vector<int> s[max_n];
vector<int> e[max_n];
int main() {
// ll start = clock();
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> l[i] >> r[i] >> a[i];
s[l[i]].pb(i);
e[r[i]].pb(i);
}
ll res = 0, ans;
segment_tree st(n + 1);
for (int i = 1; i <= n; i++) {
for (int id : s[i])
st.update(0, i - 1, a[id]);
ans = st.query(0, i - 1);
res = max(res, ans);
st.update(i, i, ans);
for (int id : e[i])
st.update(0, l[id] - 1, -a[id]);
}
cout << res << endl;
// cerr << (clock() - start) / (CLOCKS_PER_SEC*1.0) << endl;
return 0;
} | // in the name of Allah
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define ll long long
#define double long double
#define sz(x) ((int)(x.size()))
#define fr first
#define se second
#define inf 1e18
#define max_n 200002
#define mod 1000000007
ll add(ll a, ll b) {
a += b;
if (a >= mod)
return a - mod;
return a;
}
ll mul(ll a, ll b) {
a *= b;
if (a >= mod)
return a % mod;
return a;
}
ll power(ll a, ll b) {
ll p = 1;
while (b) {
if (b & 1)
p = mul(p, a);
a = mul(a, a);
b /= 2;
}
return p;
}
/*
const int _N = 1234567;
ll F[_N];
ll IF[_N];
void init() {
F[0] = 1;
for(int i=1; i<_N; i++) F[i] = mul(F[i-1], i);
IF[_N-1] = power(F[_N-1], mod-2);
for(int i=_N-2; i>=0; i--) IF[i] = mul(IF[i+1], i+1);
}
ll ncr(ll x, ll y) {
if(y > x || y < 0) return 0;
return mul(F[x], mul(IF[x-y], IF[y]));
}
/**/
class mxLazySegTree {
public:
int sz;
vector<ll> tree, lazy;
mxLazySegTree(int _sz) {
sz = _sz;
tree.assign(sz * 4, 0);
lazy.assign(sz * 4, 0);
}
// update
void update(int p, int L, int R, int l, int r, ll val) {
if (lazy[p] != 0) {
tree[p] += lazy[p];
if (L != R) {
lazy[2 * p] += lazy[p];
lazy[2 * p + 1] += lazy[p];
}
lazy[p] = 0;
}
if (R < l || r < L)
return;
if (l <= L && R <= r) {
tree[p] += val;
lazy[2 * p] += val;
lazy[2 * p + 1] += val;
return;
}
int M = (L + R) / 2;
update(2 * p, L, M, l, r, val);
update(2 * p + 1, M + 1, R, l, r, val);
tree[p] = max(tree[2 * p], tree[2 * p + 1]);
}
void update(int l, int r, ll val) { update(1, 0, sz - 1, l, r, val); }
// query
ll query(int p, int L, int R, int l, int r) {
if (R < l || r < L)
return -1e18;
if (lazy[p] != 0) {
tree[p] += lazy[p];
if (L != R) {
lazy[2 * p] += lazy[p];
lazy[2 * p + 1] += lazy[p];
}
lazy[p] = 0;
}
if (l <= L && R <= r)
return tree[p];
int M = (L + R) / 2;
return max(query(2 * p, L, M, l, r), query(2 * p + 1, M + 1, R, l, r));
}
ll query(int l, int r) { return query(1, 0, sz - 1, l, r); }
};
class segment_tree {
private:
vector<ll> tree;
ll lazy[4 * max_n];
void build(int node, int start, int end) {
if (start == end)
tree[node] = A[start];
else {
int mid = (start + end) / 2;
build(2 * node, start, mid);
build(2 * node + 1, mid + 1, end);
tree[node] = max(tree[2 * node], tree[2 * node + 1]);
}
}
void updateRange(int node, int start, int end, int l, int r, ll val) {
if (lazy[node] != 0) {
tree[node] += lazy[node];
if (start != end) {
lazy[node * 2] += lazy[node];
lazy[node * 2 + 1] += lazy[node];
}
lazy[node] = 0;
}
if (start > end || start > r || end < l)
return;
if (start >= l && end <= r) {
tree[node] += val;
if (start != end) {
lazy[node * 2] += val;
lazy[node * 2 + 1] += val;
}
return;
}
int mid = (start + end) / 2;
updateRange(node * 2, start, mid, l, r, val);
updateRange(node * 2 + 1, mid + 1, end, l, r, val);
tree[node] = max(tree[node * 2], tree[node * 2 + 1]);
}
ll queryRange(int node, int start, int end, int l, int r) {
if (start > end || start > r || end < l)
return -inf;
if (lazy[node] != 0) {
tree[node] += lazy[node];
if (start != end) {
lazy[node * 2] += lazy[node];
lazy[node * 2 + 1] += lazy[node];
}
lazy[node] = 0;
}
if (start >= l && end <= r)
return tree[node];
int mid = (start + end) / 2;
ll p1 = queryRange(node * 2, start, mid, l, r);
ll p2 = queryRange(node * 2 + 1, mid + 1, end, l, r);
return max(p1, p2);
}
public:
int n;
vector<ll> A;
segment_tree(int sz) {
A.assign(sz, 0);
n = A.size();
tree.assign(4 * n, 0);
memset(lazy, 0, sizeof lazy);
}
segment_tree(const vector<ll> &v) {
A = v;
n = A.size();
tree.assign(4 * n, 0);
memset(lazy, -1, sizeof lazy);
build(1, 0, n - 1);
}
ll query(int l, int r) { return queryRange(1, 0, n - 1, l, r); }
void update(int l, int r, ll val) { updateRange(1, 0, n - 1, l, r, val); }
};
int n, m;
ll a[max_n];
int l[max_n], r[max_n];
vector<int> s[max_n];
vector<int> e[max_n];
int main() {
// ll start = clock();
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> l[i] >> r[i] >> a[i];
s[l[i]].pb(i);
e[r[i]].pb(i);
}
ll res = 0, ans;
segment_tree st(n + 1);
for (int i = 1; i <= n; i++) {
for (int id : s[i])
st.update(0, i - 1, a[id]);
ans = st.query(0, i - 1);
res = max(res, ans);
st.update(i, i, ans);
for (int id : e[i])
st.update(0, l[id] - 1, -a[id]);
}
cout << res << endl;
// cerr << (clock() - start) / (CLOCKS_PER_SEC*1.0) << endl;
return 0;
} | [
"preprocessor.define.value.change",
"literal.integer.change"
] | 986,733 | 986,739 | u812771098 | cpp |
p03182 | // in the name of Allah
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define ll long long
#define double long double
#define sz(x) ((int)(x.size()))
#define fr first
#define se second
#define inf 1e9
#define max_n 200002
#define mod 1000000007
ll add(ll a, ll b) {
a += b;
if (a >= mod)
return a - mod;
return a;
}
ll mul(ll a, ll b) {
a *= b;
if (a >= mod)
return a % mod;
return a;
}
ll power(ll a, ll b) {
ll p = 1;
while (b) {
if (b & 1)
p = mul(p, a);
a = mul(a, a);
b /= 2;
}
return p;
}
/*
const int _N = 1234567;
ll F[_N];
ll IF[_N];
void init() {
F[0] = 1;
for(int i=1; i<_N; i++) F[i] = mul(F[i-1], i);
IF[_N-1] = power(F[_N-1], mod-2);
for(int i=_N-2; i>=0; i--) IF[i] = mul(IF[i+1], i+1);
}
ll ncr(ll x, ll y) {
if(y > x || y < 0) return 0;
return mul(F[x], mul(IF[x-y], IF[y]));
}
/**/
class mxLazySegTree {
public:
int sz;
vector<ll> tree, lazy;
mxLazySegTree(int _sz) {
sz = _sz;
tree.assign(sz * 4, 0);
lazy.assign(sz * 4, 0);
}
// update
void update(int p, int L, int R, int l, int r, ll val) {
if (R < l || r < L)
return;
if (l <= L && R <= r) {
tree[p] += val;
lazy[2 * p] += val;
lazy[2 * p + 1] += val;
return;
}
int M = (L + R) / 2;
update(2 * p, L, M, l, r, val);
update(2 * p + 1, M + 1, R, l, r, val);
tree[p] = max(tree[2 * p], tree[2 * p + 1]);
}
void update(int l, int r, ll val) { update(1, 0, sz - 1, l, r, val); }
// query
ll query(int p, int L, int R, int l, int r) {
if (R < l || r < L)
return -1e18;
if (lazy[p] != 0) {
tree[p] += lazy[p];
lazy[2 * p] += lazy[p];
lazy[2 * p + 1] += lazy[p];
lazy[p] = 0;
}
if (l <= L && R <= r)
return tree[p];
int M = (L + R) / 2;
return max(query(2 * p, L, M, l, r), query(2 * p + 1, M + 1, R, l, r));
}
ll query(int l, int r) { return query(1, 0, sz - 1, l, r); }
};
int n, m;
ll a[max_n];
int l[max_n], r[max_n];
vector<int> s[max_n];
vector<int> e[max_n];
int main() {
// ll start = clock();
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> l[i] >> r[i] >> a[i];
s[l[i]].pb(i);
e[r[i]].pb(i);
}
ll res = 0, ans;
mxLazySegTree st(n + 1);
for (int i = 1; i <= n; i++) {
for (int id : s[i])
st.update(0, i - 1, a[id]);
ans = st.query(0, i - 1);
res = max(res, ans);
st.update(i, i, ans);
for (int id : e[i])
st.update(0, l[id] - 1, -a[id]);
}
cout << res << endl;
// cerr << (clock() - start) / (CLOCKS_PER_SEC*1.0) << endl;
return 0;
} | // in the name of Allah
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define ll long long
#define double long double
#define sz(x) ((int)(x.size()))
#define fr first
#define se second
#define inf 1e18
#define max_n 200002
#define mod 1000000007
ll add(ll a, ll b) {
a += b;
if (a >= mod)
return a - mod;
return a;
}
ll mul(ll a, ll b) {
a *= b;
if (a >= mod)
return a % mod;
return a;
}
ll power(ll a, ll b) {
ll p = 1;
while (b) {
if (b & 1)
p = mul(p, a);
a = mul(a, a);
b /= 2;
}
return p;
}
/*
const int _N = 1234567;
ll F[_N];
ll IF[_N];
void init() {
F[0] = 1;
for(int i=1; i<_N; i++) F[i] = mul(F[i-1], i);
IF[_N-1] = power(F[_N-1], mod-2);
for(int i=_N-2; i>=0; i--) IF[i] = mul(IF[i+1], i+1);
}
ll ncr(ll x, ll y) {
if(y > x || y < 0) return 0;
return mul(F[x], mul(IF[x-y], IF[y]));
}
/**/
class mxLazySegTree {
public:
int sz;
vector<ll> tree, lazy;
mxLazySegTree(int _sz) {
sz = _sz;
tree.assign(sz * 4, 0);
lazy.assign(sz * 4, 0);
}
// update
void update(int p, int L, int R, int l, int r, ll val) {
if (lazy[p] != 0) {
tree[p] += lazy[p];
if (L != R) {
lazy[2 * p] += lazy[p];
lazy[2 * p + 1] += lazy[p];
}
lazy[p] = 0;
}
if (R < l || r < L)
return;
if (l <= L && R <= r) {
tree[p] += val;
lazy[2 * p] += val;
lazy[2 * p + 1] += val;
return;
}
int M = (L + R) / 2;
update(2 * p, L, M, l, r, val);
update(2 * p + 1, M + 1, R, l, r, val);
tree[p] = max(tree[2 * p], tree[2 * p + 1]);
}
void update(int l, int r, ll val) { update(1, 0, sz - 1, l, r, val); }
// query
ll query(int p, int L, int R, int l, int r) {
if (R < l || r < L)
return -1e18;
if (lazy[p] != 0) {
tree[p] += lazy[p];
if (L != R) {
lazy[2 * p] += lazy[p];
lazy[2 * p + 1] += lazy[p];
}
lazy[p] = 0;
}
if (l <= L && R <= r)
return tree[p];
int M = (L + R) / 2;
return max(query(2 * p, L, M, l, r), query(2 * p + 1, M + 1, R, l, r));
}
ll query(int l, int r) { return query(1, 0, sz - 1, l, r); }
};
class segment_tree {
private:
vector<ll> tree;
ll lazy[4 * max_n];
void build(int node, int start, int end) {
if (start == end)
tree[node] = A[start];
else {
int mid = (start + end) / 2;
build(2 * node, start, mid);
build(2 * node + 1, mid + 1, end);
tree[node] = max(tree[2 * node], tree[2 * node + 1]);
}
}
void updateRange(int node, int start, int end, int l, int r, ll val) {
if (lazy[node] != 0) {
tree[node] += lazy[node];
if (start != end) {
lazy[node * 2] += lazy[node];
lazy[node * 2 + 1] += lazy[node];
}
lazy[node] = 0;
}
if (start > end || start > r || end < l)
return;
if (start >= l && end <= r) {
tree[node] += val;
if (start != end) {
lazy[node * 2] += val;
lazy[node * 2 + 1] += val;
}
return;
}
int mid = (start + end) / 2;
updateRange(node * 2, start, mid, l, r, val);
updateRange(node * 2 + 1, mid + 1, end, l, r, val);
tree[node] = max(tree[node * 2], tree[node * 2 + 1]);
}
ll queryRange(int node, int start, int end, int l, int r) {
if (start > end || start > r || end < l)
return -inf;
if (lazy[node] != 0) {
tree[node] += lazy[node];
if (start != end) {
lazy[node * 2] += lazy[node];
lazy[node * 2 + 1] += lazy[node];
}
lazy[node] = 0;
}
if (start >= l && end <= r)
return tree[node];
int mid = (start + end) / 2;
ll p1 = queryRange(node * 2, start, mid, l, r);
ll p2 = queryRange(node * 2 + 1, mid + 1, end, l, r);
return max(p1, p2);
}
public:
int n;
vector<ll> A;
segment_tree(int sz) {
A.assign(sz, 0);
n = A.size();
tree.assign(4 * n, 0);
memset(lazy, 0, sizeof lazy);
}
segment_tree(const vector<ll> &v) {
A = v;
n = A.size();
tree.assign(4 * n, 0);
memset(lazy, -1, sizeof lazy);
build(1, 0, n - 1);
}
ll query(int l, int r) { return queryRange(1, 0, n - 1, l, r); }
void update(int l, int r, ll val) { updateRange(1, 0, n - 1, l, r, val); }
};
int n, m;
ll a[max_n];
int l[max_n], r[max_n];
vector<int> s[max_n];
vector<int> e[max_n];
int main() {
// ll start = clock();
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> l[i] >> r[i] >> a[i];
s[l[i]].pb(i);
e[r[i]].pb(i);
}
ll res = 0, ans;
segment_tree st(n + 1);
for (int i = 1; i <= n; i++) {
for (int id : s[i])
st.update(0, i - 1, a[id]);
ans = st.query(0, i - 1);
res = max(res, ans);
st.update(i, i, ans);
for (int id : e[i])
st.update(0, l[id] - 1, -a[id]);
}
cout << res << endl;
// cerr << (clock() - start) / (CLOCKS_PER_SEC*1.0) << endl;
return 0;
} | [
"preprocessor.define.value.change",
"literal.float.change"
] | 986,735 | 986,739 | u812771098 | cpp |
p03182 | // in the name of Allah
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define ll long long
#define double long double
#define sz(x) ((int)(x.size()))
#define fr first
#define se second
#define inf 1e18
#define max_n 2000002
#define mod 1000000007
ll add(ll a, ll b) {
a += b;
if (a >= mod)
return a - mod;
return a;
}
ll mul(ll a, ll b) {
a *= b;
if (a >= mod)
return a % mod;
return a;
}
ll power(ll a, ll b) {
ll p = 1;
while (b) {
if (b & 1)
p = mul(p, a);
a = mul(a, a);
b /= 2;
}
return p;
}
/*
const int _N = 1234567;
ll F[_N];
ll IF[_N];
void init() {
F[0] = 1;
for(int i=1; i<_N; i++) F[i] = mul(F[i-1], i);
IF[_N-1] = power(F[_N-1], mod-2);
for(int i=_N-2; i>=0; i--) IF[i] = mul(IF[i+1], i+1);
}
ll ncr(ll x, ll y) {
if(y > x || y < 0) return 0;
return mul(F[x], mul(IF[x-y], IF[y]));
}
/**/
/*
class mxLazySegTree {
public:
int sz;
vector <ll> tree, lazy;
mxLazySegTree(int _sz) {
sz = _sz;
tree.assign(sz*4, 0);
lazy.assign(sz*4, 0);
}
// update
void update(int p, int L, int R, int l, int r, ll val) {
if(R < l || r < L) return;
if(l <= L && R <= r) {
tree[p] += val;
lazy[2*p] += val;
lazy[2*p+1] += val;
return;
}
int M = (L+R)/2;
update(2*p, L, M, l, r, val);
update(2*p+1, M+1, R, l, r, val);
tree[p] = max(tree[2*p], tree[2*p+1]);
}
void update(int l, int r, ll val) {
update(1, 0, sz-1, l, r, val);
}
// query
ll query(int p, int L, int R, int l, int r) {
if(R < l || r < L) return -1e18;
if(lazy[p] != 0) {
tree[p] += lazy[p];
lazy[2*p] += lazy[p];
lazy[2*p+1] += lazy[p];
lazy[p] = 0;
}
if(l <= L && R <= r) return tree[p];
int M = (L+R)/2;
return max(query(2*p, L, M, l, r), query(2*p+1, M+1, R, l, r));
}
ll query(int l, int r) {
return query(1, 0, sz-1, l, r);
}
};
/**/
/*
class mxLazySegTree {
public:
int sz;
vector <ll> tree, lazy;
mxLazySegTree(int _sz) {
sz = _sz;
tree.assign(sz*4, 0);
lazy.assign(sz*4, 0);
}
// update
void update(int l, int r, ll val) {
for(int i=l; i<=r; i++) tree[i] += val;
}
// query
ll query(int l, int r) {
ll res = -inf;
for(int i=l; i<=r; i++) res = max(res, tree[i]);
return res;
}
};
/**/
class segment_tree {
private:
vector<ll> tree;
ll lazy[4 * max_n];
void build(int node, int start, int end) {
if (start == end)
tree[node] = A[start];
else {
int mid = (start + end) / 2;
build(2 * node, start, mid);
build(2 * node + 1, mid + 1, end);
tree[node] = max(tree[2 * node], tree[2 * node + 1]);
}
}
void updateRange(int node, int start, int end, int l, int r, ll val) {
if (lazy[node] != 0) {
tree[node] += lazy[node];
if (start != end) {
lazy[node * 2] += lazy[node];
lazy[node * 2 + 1] += lazy[node];
}
lazy[node] = 0;
}
if (start > end || start > r || end < l)
return;
if (start >= l && end <= r) {
tree[node] += val;
if (start != end) {
lazy[node * 2] += val;
lazy[node * 2 + 1] += val;
}
return;
}
int mid = (start + end) / 2;
updateRange(node * 2, start, mid, l, r, val);
updateRange(node * 2 + 1, mid + 1, end, l, r, val);
tree[node] = max(tree[node * 2], tree[node * 2 + 1]);
}
ll queryRange(int node, int start, int end, int l, int r) {
if (start > end || start > r || end < l)
return -inf;
if (lazy[node] != 0) {
tree[node] += lazy[node];
if (start != end) {
lazy[node * 2] += lazy[node];
lazy[node * 2 + 1] += lazy[node];
}
lazy[node] = 0;
}
if (start >= l && end <= r)
return tree[node];
int mid = (start + end) / 2;
ll p1 = queryRange(node * 2, start, mid, l, r);
ll p2 = queryRange(node * 2 + 1, mid + 1, end, l, r);
return max(p1, p2);
}
public:
int n;
vector<ll> A;
segment_tree(int sz) {
A.assign(sz, 0);
n = A.size();
tree.assign(4 * n, 0);
memset(lazy, 0, sizeof lazy);
build(1, 0, n - 1);
}
segment_tree(const vector<ll> &v) {
A = v;
n = A.size();
tree.assign(4 * n, 0);
memset(lazy, -1, sizeof lazy);
build(1, 0, n - 1);
}
ll query(int l, int r) { return queryRange(1, 0, n - 1, l, r); }
void update(int l, int r, int val) { updateRange(1, 0, n - 1, l, r, val); }
};
int n, m;
ll a[max_n];
int l[max_n], r[max_n];
vector<int> s[max_n];
vector<int> e[max_n];
int main() {
// ll start = clock();
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> l[i] >> r[i] >> a[i];
s[l[i]].pb(i);
e[r[i]].pb(i);
}
ll res = 0, ans;
segment_tree st(n + 1);
for (int i = 1; i <= n; i++) {
for (int id : s[i])
st.update(0, i - 1, a[id]);
ans = st.query(0, i - 1);
res = max(res, ans);
st.update(i, i, ans);
for (int id : e[i])
st.update(0, l[id] - 1, -a[id]);
}
cout << res << endl;
// cerr << (clock() - start) / (CLOCKS_PER_SEC*1.0) << endl;
return 0;
} | // in the name of Allah
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define ll long long
#define double long double
#define sz(x) ((int)(x.size()))
#define fr first
#define se second
#define inf 1e18
#define max_n 200002
#define mod 1000000007
ll add(ll a, ll b) {
a += b;
if (a >= mod)
return a - mod;
return a;
}
ll mul(ll a, ll b) {
a *= b;
if (a >= mod)
return a % mod;
return a;
}
ll power(ll a, ll b) {
ll p = 1;
while (b) {
if (b & 1)
p = mul(p, a);
a = mul(a, a);
b /= 2;
}
return p;
}
/*
const int _N = 1234567;
ll F[_N];
ll IF[_N];
void init() {
F[0] = 1;
for(int i=1; i<_N; i++) F[i] = mul(F[i-1], i);
IF[_N-1] = power(F[_N-1], mod-2);
for(int i=_N-2; i>=0; i--) IF[i] = mul(IF[i+1], i+1);
}
ll ncr(ll x, ll y) {
if(y > x || y < 0) return 0;
return mul(F[x], mul(IF[x-y], IF[y]));
}
/**/
class mxLazySegTree {
public:
int sz;
vector<ll> tree, lazy;
mxLazySegTree(int _sz) {
sz = _sz;
tree.assign(sz * 4, 0);
lazy.assign(sz * 4, 0);
}
// update
void update(int p, int L, int R, int l, int r, ll val) {
if (lazy[p] != 0) {
tree[p] += lazy[p];
if (L != R) {
lazy[2 * p] += lazy[p];
lazy[2 * p + 1] += lazy[p];
}
lazy[p] = 0;
}
if (R < l || r < L)
return;
if (l <= L && R <= r) {
tree[p] += val;
lazy[2 * p] += val;
lazy[2 * p + 1] += val;
return;
}
int M = (L + R) / 2;
update(2 * p, L, M, l, r, val);
update(2 * p + 1, M + 1, R, l, r, val);
tree[p] = max(tree[2 * p], tree[2 * p + 1]);
}
void update(int l, int r, ll val) { update(1, 0, sz - 1, l, r, val); }
// query
ll query(int p, int L, int R, int l, int r) {
if (R < l || r < L)
return -1e18;
if (lazy[p] != 0) {
tree[p] += lazy[p];
if (L != R) {
lazy[2 * p] += lazy[p];
lazy[2 * p + 1] += lazy[p];
}
lazy[p] = 0;
}
if (l <= L && R <= r)
return tree[p];
int M = (L + R) / 2;
return max(query(2 * p, L, M, l, r), query(2 * p + 1, M + 1, R, l, r));
}
ll query(int l, int r) { return query(1, 0, sz - 1, l, r); }
};
class segment_tree {
private:
vector<ll> tree;
ll lazy[4 * max_n];
void build(int node, int start, int end) {
if (start == end)
tree[node] = A[start];
else {
int mid = (start + end) / 2;
build(2 * node, start, mid);
build(2 * node + 1, mid + 1, end);
tree[node] = max(tree[2 * node], tree[2 * node + 1]);
}
}
void updateRange(int node, int start, int end, int l, int r, ll val) {
if (lazy[node] != 0) {
tree[node] += lazy[node];
if (start != end) {
lazy[node * 2] += lazy[node];
lazy[node * 2 + 1] += lazy[node];
}
lazy[node] = 0;
}
if (start > end || start > r || end < l)
return;
if (start >= l && end <= r) {
tree[node] += val;
if (start != end) {
lazy[node * 2] += val;
lazy[node * 2 + 1] += val;
}
return;
}
int mid = (start + end) / 2;
updateRange(node * 2, start, mid, l, r, val);
updateRange(node * 2 + 1, mid + 1, end, l, r, val);
tree[node] = max(tree[node * 2], tree[node * 2 + 1]);
}
ll queryRange(int node, int start, int end, int l, int r) {
if (start > end || start > r || end < l)
return -inf;
if (lazy[node] != 0) {
tree[node] += lazy[node];
if (start != end) {
lazy[node * 2] += lazy[node];
lazy[node * 2 + 1] += lazy[node];
}
lazy[node] = 0;
}
if (start >= l && end <= r)
return tree[node];
int mid = (start + end) / 2;
ll p1 = queryRange(node * 2, start, mid, l, r);
ll p2 = queryRange(node * 2 + 1, mid + 1, end, l, r);
return max(p1, p2);
}
public:
int n;
vector<ll> A;
segment_tree(int sz) {
A.assign(sz, 0);
n = A.size();
tree.assign(4 * n, 0);
memset(lazy, 0, sizeof lazy);
build(1, 0, n - 1);
}
segment_tree(const vector<ll> &v) {
A = v;
n = A.size();
tree.assign(4 * n, 0);
memset(lazy, -1, sizeof lazy);
build(1, 0, n - 1);
}
ll query(int l, int r) { return queryRange(1, 0, n - 1, l, r); }
void update(int l, int r, ll val) { updateRange(1, 0, n - 1, l, r, val); }
};
int n, m;
ll a[max_n];
int l[max_n], r[max_n];
vector<int> s[max_n];
vector<int> e[max_n];
int main() {
// ll start = clock();
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> l[i] >> r[i] >> a[i];
s[l[i]].pb(i);
e[r[i]].pb(i);
}
ll res = 0, ans;
segment_tree st(n + 1);
for (int i = 1; i <= n; i++) {
for (int id : s[i])
st.update(0, i - 1, a[id]);
ans = st.query(0, i - 1);
res = max(res, ans);
st.update(i, i, ans);
for (int id : e[i])
st.update(0, l[id] - 1, -a[id]);
}
cout << res << endl;
// cerr << (clock() - start) / (CLOCKS_PER_SEC*1.0) << endl;
return 0;
} | [
"preprocessor.define.value.change",
"literal.integer.change"
] | 986,733 | 986,740 | u812771098 | cpp |
p03182 | // in the name of Allah
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define ll long long
#define double long double
#define sz(x) ((int)(x.size()))
#define fr first
#define se second
#define inf 1e9
#define max_n 200002
#define mod 1000000007
ll add(ll a, ll b) {
a += b;
if (a >= mod)
return a - mod;
return a;
}
ll mul(ll a, ll b) {
a *= b;
if (a >= mod)
return a % mod;
return a;
}
ll power(ll a, ll b) {
ll p = 1;
while (b) {
if (b & 1)
p = mul(p, a);
a = mul(a, a);
b /= 2;
}
return p;
}
/*
const int _N = 1234567;
ll F[_N];
ll IF[_N];
void init() {
F[0] = 1;
for(int i=1; i<_N; i++) F[i] = mul(F[i-1], i);
IF[_N-1] = power(F[_N-1], mod-2);
for(int i=_N-2; i>=0; i--) IF[i] = mul(IF[i+1], i+1);
}
ll ncr(ll x, ll y) {
if(y > x || y < 0) return 0;
return mul(F[x], mul(IF[x-y], IF[y]));
}
/**/
class mxLazySegTree {
public:
int sz;
vector<ll> tree, lazy;
mxLazySegTree(int _sz) {
sz = _sz;
tree.assign(sz * 4, 0);
lazy.assign(sz * 4, 0);
}
// update
void update(int p, int L, int R, int l, int r, ll val) {
if (R < l || r < L)
return;
if (l <= L && R <= r) {
tree[p] += val;
lazy[2 * p] += val;
lazy[2 * p + 1] += val;
return;
}
int M = (L + R) / 2;
update(2 * p, L, M, l, r, val);
update(2 * p + 1, M + 1, R, l, r, val);
tree[p] = max(tree[2 * p], tree[2 * p + 1]);
}
void update(int l, int r, ll val) { update(1, 0, sz - 1, l, r, val); }
// query
ll query(int p, int L, int R, int l, int r) {
if (R < l || r < L)
return -1e18;
if (lazy[p] != 0) {
tree[p] += lazy[p];
lazy[2 * p] += lazy[p];
lazy[2 * p + 1] += lazy[p];
lazy[p] = 0;
}
if (l <= L && R <= r)
return tree[p];
int M = (L + R) / 2;
return max(query(2 * p, L, M, l, r), query(2 * p + 1, M + 1, R, l, r));
}
ll query(int l, int r) { return query(1, 0, sz - 1, l, r); }
};
int n, m;
ll a[max_n];
int l[max_n], r[max_n];
vector<int> s[max_n];
vector<int> e[max_n];
int main() {
// ll start = clock();
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> l[i] >> r[i] >> a[i];
s[l[i]].pb(i);
e[r[i]].pb(i);
}
ll res = 0, ans;
mxLazySegTree st(n + 1);
for (int i = 1; i <= n; i++) {
for (int id : s[i])
st.update(0, i - 1, a[id]);
ans = st.query(0, i - 1);
res = max(res, ans);
st.update(i, i, ans);
for (int id : e[i])
st.update(0, l[id] - 1, -a[id]);
}
cout << res << endl;
// cerr << (clock() - start) / (CLOCKS_PER_SEC*1.0) << endl;
return 0;
} | // in the name of Allah
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define ll long long
#define double long double
#define sz(x) ((int)(x.size()))
#define fr first
#define se second
#define inf 1e18
#define max_n 200002
#define mod 1000000007
ll add(ll a, ll b) {
a += b;
if (a >= mod)
return a - mod;
return a;
}
ll mul(ll a, ll b) {
a *= b;
if (a >= mod)
return a % mod;
return a;
}
ll power(ll a, ll b) {
ll p = 1;
while (b) {
if (b & 1)
p = mul(p, a);
a = mul(a, a);
b /= 2;
}
return p;
}
/*
const int _N = 1234567;
ll F[_N];
ll IF[_N];
void init() {
F[0] = 1;
for(int i=1; i<_N; i++) F[i] = mul(F[i-1], i);
IF[_N-1] = power(F[_N-1], mod-2);
for(int i=_N-2; i>=0; i--) IF[i] = mul(IF[i+1], i+1);
}
ll ncr(ll x, ll y) {
if(y > x || y < 0) return 0;
return mul(F[x], mul(IF[x-y], IF[y]));
}
/**/
class mxLazySegTree {
public:
int sz;
vector<ll> tree, lazy;
mxLazySegTree(int _sz) {
sz = _sz;
tree.assign(sz * 4, 0);
lazy.assign(sz * 4, 0);
}
// update
void update(int p, int L, int R, int l, int r, ll val) {
if (lazy[p] != 0) {
tree[p] += lazy[p];
if (L != R) {
lazy[2 * p] += lazy[p];
lazy[2 * p + 1] += lazy[p];
}
lazy[p] = 0;
}
if (R < l || r < L)
return;
if (l <= L && R <= r) {
tree[p] += val;
lazy[2 * p] += val;
lazy[2 * p + 1] += val;
return;
}
int M = (L + R) / 2;
update(2 * p, L, M, l, r, val);
update(2 * p + 1, M + 1, R, l, r, val);
tree[p] = max(tree[2 * p], tree[2 * p + 1]);
}
void update(int l, int r, ll val) { update(1, 0, sz - 1, l, r, val); }
// query
ll query(int p, int L, int R, int l, int r) {
if (R < l || r < L)
return -1e18;
if (lazy[p] != 0) {
tree[p] += lazy[p];
if (L != R) {
lazy[2 * p] += lazy[p];
lazy[2 * p + 1] += lazy[p];
}
lazy[p] = 0;
}
if (l <= L && R <= r)
return tree[p];
int M = (L + R) / 2;
return max(query(2 * p, L, M, l, r), query(2 * p + 1, M + 1, R, l, r));
}
ll query(int l, int r) { return query(1, 0, sz - 1, l, r); }
};
class segment_tree {
private:
vector<ll> tree;
ll lazy[4 * max_n];
void build(int node, int start, int end) {
if (start == end)
tree[node] = A[start];
else {
int mid = (start + end) / 2;
build(2 * node, start, mid);
build(2 * node + 1, mid + 1, end);
tree[node] = max(tree[2 * node], tree[2 * node + 1]);
}
}
void updateRange(int node, int start, int end, int l, int r, ll val) {
if (lazy[node] != 0) {
tree[node] += lazy[node];
if (start != end) {
lazy[node * 2] += lazy[node];
lazy[node * 2 + 1] += lazy[node];
}
lazy[node] = 0;
}
if (start > end || start > r || end < l)
return;
if (start >= l && end <= r) {
tree[node] += val;
if (start != end) {
lazy[node * 2] += val;
lazy[node * 2 + 1] += val;
}
return;
}
int mid = (start + end) / 2;
updateRange(node * 2, start, mid, l, r, val);
updateRange(node * 2 + 1, mid + 1, end, l, r, val);
tree[node] = max(tree[node * 2], tree[node * 2 + 1]);
}
ll queryRange(int node, int start, int end, int l, int r) {
if (start > end || start > r || end < l)
return -inf;
if (lazy[node] != 0) {
tree[node] += lazy[node];
if (start != end) {
lazy[node * 2] += lazy[node];
lazy[node * 2 + 1] += lazy[node];
}
lazy[node] = 0;
}
if (start >= l && end <= r)
return tree[node];
int mid = (start + end) / 2;
ll p1 = queryRange(node * 2, start, mid, l, r);
ll p2 = queryRange(node * 2 + 1, mid + 1, end, l, r);
return max(p1, p2);
}
public:
int n;
vector<ll> A;
segment_tree(int sz) {
A.assign(sz, 0);
n = A.size();
tree.assign(4 * n, 0);
memset(lazy, 0, sizeof lazy);
build(1, 0, n - 1);
}
segment_tree(const vector<ll> &v) {
A = v;
n = A.size();
tree.assign(4 * n, 0);
memset(lazy, -1, sizeof lazy);
build(1, 0, n - 1);
}
ll query(int l, int r) { return queryRange(1, 0, n - 1, l, r); }
void update(int l, int r, ll val) { updateRange(1, 0, n - 1, l, r, val); }
};
int n, m;
ll a[max_n];
int l[max_n], r[max_n];
vector<int> s[max_n];
vector<int> e[max_n];
int main() {
// ll start = clock();
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> l[i] >> r[i] >> a[i];
s[l[i]].pb(i);
e[r[i]].pb(i);
}
ll res = 0, ans;
segment_tree st(n + 1);
for (int i = 1; i <= n; i++) {
for (int id : s[i])
st.update(0, i - 1, a[id]);
ans = st.query(0, i - 1);
res = max(res, ans);
st.update(i, i, ans);
for (int id : e[i])
st.update(0, l[id] - 1, -a[id]);
}
cout << res << endl;
// cerr << (clock() - start) / (CLOCKS_PER_SEC*1.0) << endl;
return 0;
} | [
"preprocessor.define.value.change",
"literal.float.change"
] | 986,735 | 986,740 | u812771098 | cpp |
p03182 | // in the name of Allah
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define ll long long
#define double long double
#define sz(x) ((int)(x.size()))
#define fr first
#define se second
#define inf 1e9
#define max_n 200002
#define mod 1000000007
ll add(ll a, ll b) {
a += b;
if (a >= mod)
return a - mod;
return a;
}
ll mul(ll a, ll b) {
a *= b;
if (a >= mod)
return a % mod;
return a;
}
ll power(ll a, ll b) {
ll p = 1;
while (b) {
if (b & 1)
p = mul(p, a);
a = mul(a, a);
b /= 2;
}
return p;
}
/*
const int _N = 1234567;
ll F[_N];
ll IF[_N];
void init() {
F[0] = 1;
for(int i=1; i<_N; i++) F[i] = mul(F[i-1], i);
IF[_N-1] = power(F[_N-1], mod-2);
for(int i=_N-2; i>=0; i--) IF[i] = mul(IF[i+1], i+1);
}
ll ncr(ll x, ll y) {
if(y > x || y < 0) return 0;
return mul(F[x], mul(IF[x-y], IF[y]));
}
/**/
class mxLazySegTree {
public:
int sz;
vector<ll> tree, lazy;
mxLazySegTree(int _sz) {
sz = _sz;
tree.assign(sz * 4, 0);
lazy.assign(sz * 4, 0);
}
// update
void update(int p, int L, int R, int l, int r, ll val) {
if (R < l || r < L)
return;
if (l <= L && R <= r) {
tree[p] += val;
lazy[2 * p] += val;
lazy[2 * p + 1] += val;
return;
}
int M = (L + R) / 2;
update(2 * p, L, M, l, r, val);
update(2 * p + 1, M + 1, R, l, r, val);
tree[p] = max(tree[2 * p], tree[2 * p + 1]);
}
void update(int l, int r, ll val) { update(1, 0, sz - 1, l, r, val); }
// query
ll query(int p, int L, int R, int l, int r) {
if (R < l || r < L)
return -1e18;
if (lazy[p] != 0) {
tree[p] += lazy[p];
lazy[2 * p] += lazy[p];
lazy[2 * p + 1] += lazy[p];
lazy[p] = 0;
}
if (l <= L && R <= r)
return tree[p];
int M = (L + R) / 2;
return max(query(2 * p, L, M, l, r), query(2 * p + 1, M + 1, R, l, r));
}
ll query(int l, int r) { return query(1, 0, sz - 1, l, r); }
};
int n, m;
ll a[max_n];
int l[max_n], r[max_n];
vector<int> s[max_n];
vector<int> e[max_n];
int main() {
// ll start = clock();
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> l[i] >> r[i] >> a[i];
s[l[i]].pb(i);
e[r[i]].pb(i);
}
ll res = 0, ans;
mxLazySegTree st(n + 1);
for (int i = 1; i <= n; i++) {
for (int id : s[i])
st.update(0, i - 1, a[id]);
ans = st.query(0, i - 1);
res = max(res, ans);
st.update(i, i, ans);
for (int id : e[i])
st.update(0, l[id] - 1, -a[id]);
}
cout << res << endl;
// cerr << (clock() - start) / (CLOCKS_PER_SEC*1.0) << endl;
return 0;
} | // in the name of Allah
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define ll long long
#define double long double
#define sz(x) ((int)(x.size()))
#define fr first
#define se second
#define inf 1e18
#define max_n 2000002
#define mod 1000000007
ll add(ll a, ll b) {
a += b;
if (a >= mod)
return a - mod;
return a;
}
ll mul(ll a, ll b) {
a *= b;
if (a >= mod)
return a % mod;
return a;
}
ll power(ll a, ll b) {
ll p = 1;
while (b) {
if (b & 1)
p = mul(p, a);
a = mul(a, a);
b /= 2;
}
return p;
}
/*
const int _N = 1234567;
ll F[_N];
ll IF[_N];
void init() {
F[0] = 1;
for(int i=1; i<_N; i++) F[i] = mul(F[i-1], i);
IF[_N-1] = power(F[_N-1], mod-2);
for(int i=_N-2; i>=0; i--) IF[i] = mul(IF[i+1], i+1);
}
ll ncr(ll x, ll y) {
if(y > x || y < 0) return 0;
return mul(F[x], mul(IF[x-y], IF[y]));
}
/**/
/*
class mxLazySegTree {
public:
int sz;
vector <ll> tree, lazy;
mxLazySegTree(int _sz) {
sz = _sz;
tree.assign(sz*4, 0);
lazy.assign(sz*4, 0);
}
// update
void update(int p, int L, int R, int l, int r, ll val) {
if(R < l || r < L) return;
if(l <= L && R <= r) {
tree[p] += val;
lazy[2*p] += val;
lazy[2*p+1] += val;
return;
}
int M = (L+R)/2;
update(2*p, L, M, l, r, val);
update(2*p+1, M+1, R, l, r, val);
tree[p] = max(tree[2*p], tree[2*p+1]);
}
void update(int l, int r, ll val) {
update(1, 0, sz-1, l, r, val);
}
// query
ll query(int p, int L, int R, int l, int r) {
if(R < l || r < L) return -1e18;
if(lazy[p] != 0) {
tree[p] += lazy[p];
lazy[2*p] += lazy[p];
lazy[2*p+1] += lazy[p];
lazy[p] = 0;
}
if(l <= L && R <= r) return tree[p];
int M = (L+R)/2;
return max(query(2*p, L, M, l, r), query(2*p+1, M+1, R, l, r));
}
ll query(int l, int r) {
return query(1, 0, sz-1, l, r);
}
};
/**/
class segment_tree {
private:
vector<ll> tree, lazy;
void build(int node, int start, int end) {
if (start == end)
tree[node] = A[start];
else {
int mid = (start + end) / 2;
build(2 * node, start, mid);
build(2 * node + 1, mid + 1, end);
tree[node] = max(tree[2 * node], tree[2 * node + 1]);
}
}
void updateRange(int node, int start, int end, int l, int r, ll val) {
if (lazy[node] != 0) {
tree[node] += lazy[node];
if (start != end) {
lazy[node * 2] += lazy[node];
lazy[node * 2 + 1] += lazy[node];
}
lazy[node] = 0;
}
if (start > end || start > r || end < l)
return;
if (start >= l && end <= r) {
tree[node] += val;
if (start != end) {
lazy[node * 2] += val;
lazy[node * 2 + 1] += val;
}
return;
}
int mid = (start + end) / 2;
updateRange(node * 2, start, mid, l, r, val);
updateRange(node * 2 + 1, mid + 1, end, l, r, val);
tree[node] = max(tree[node * 2], tree[node * 2 + 1]);
}
ll queryRange(int node, int start, int end, int l, int r) {
if (start > end || start > r || end < l)
return -inf;
if (lazy[node] != 0) {
tree[node] += lazy[node];
if (start != end) {
lazy[node * 2] += lazy[node];
lazy[node * 2 + 1] += lazy[node];
}
lazy[node] = 0;
}
if (start >= l && end <= r)
return tree[node];
int mid = (start + end) / 2;
ll p1 = queryRange(node * 2, start, mid, l, r);
ll p2 = queryRange(node * 2 + 1, mid + 1, end, l, r);
return max(p1, p2);
}
public:
int n;
vector<ll> A;
segment_tree(int sz) {
A.assign(sz, 0);
n = A.size();
tree.assign(5 * n, 0);
lazy.assign(5 * n, 0);
build(1, 0, n - 1);
}
ll query(int l, int r) { return queryRange(1, 0, n - 1, l, r); }
void update(int l, int r, ll val) { updateRange(1, 0, n - 1, l, r, val); }
};
int n, m;
ll a[max_n];
int l[max_n], r[max_n];
vector<int> s[max_n];
vector<int> e[max_n];
int main() {
// ll start = clock();
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> l[i] >> r[i] >> a[i];
s[l[i]].pb(i);
e[r[i]].pb(i);
}
ll res = 0, ans;
segment_tree st(n + 1);
for (int i = 1; i <= n; i++) {
for (int id : s[i])
st.update(0, i - 1, a[id]);
ans = st.query(0, i - 1);
res = max(res, ans);
st.update(i, i, ans);
for (int id : e[i])
st.update(0, l[id] - 1, -a[id]);
}
cout << res << endl;
// cerr << (clock() - start) / (CLOCKS_PER_SEC*1.0) << endl;
return 0;
} | [
"preprocessor.define.value.change",
"literal.float.change",
"literal.integer.change"
] | 986,735 | 986,743 | u812771098 | cpp |
p03182 | #include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
//#define int ll
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;
typedef complex<double> base;
#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define mp(a, b) make_pair(a, b)
#define modsum(a, b) ((a) + (b) >= M ? (a) + (b)-M : (a) + (b))
#define modsubtract(a, b) ((a) - (b) < 0 ? (a) - (b) + M : (a) - (b))
#define modmultiply(a, b) (((a) * (b)) % M)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for (int i = 0; i < int(n); ++i)
#define cint const int &
#define SZ(a) ((int)((a).size()))
#define watch(x) cout << (#x) << " = " << (x) << endl;
const double PI = 2 * acos(0.0);
const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";
template <class T> inline ostream &operator<<(ostream &out, vector<T> &a) {
out << "{";
fori(i, SZ(a)) out << a[i] << vector<string>{", ", "}"}[i + 1 == SZ(a)];
return out;
}
void smain();
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifdef MAX_HOME
freopen("input.txt", "r", stdin);
clock_t start = clock();
#define cerr cout
#endif
cout << setprecision(12) << fixed;
smain();
#ifdef MAX_HOME
cout << "\n\n\n\n";
cout << "TOTAL EXECUTION TIME: " << float(clock() - start) / CLOCKS_PER_SEC
<< endl;
#endif
}
const int N = 2e5 + 9;
const ll oo = 1e18;
ll t[N << 2];
ll pushing[N << 2];
struct SegmentTree {
SegmentTree() {
fill(t, t + (N << 2), 0);
fill(pushing, pushing + (N << 2), 0);
}
void push(int v) {
pushing[v << 1] += pushing[v];
t[v << 1] += pushing[v];
pushing[v << 1 | 1] += pushing[v];
t[v << 1 | 1] += pushing[v];
pushing[v] = 0;
}
void upd(int v, int tl, int tr, int l, int r, ll inc) {
if (l > r)
return;
if (tl == l && tr == r) {
t[v] += inc;
pushing[v] += inc;
return;
}
push(v);
int tm = tl + tr >> 1;
upd(v << 1, tl, tm, l, min(tm, r), inc);
upd(v << 1 | 1, tm + 1, tr, max(tm + 1, l), r, inc);
t[v] = max(t[v << 1], t[v << 1 | 1]);
}
ll get(int v, int tl, int tr, int l, int r) {
if (l > r)
return -oo;
if (tl == l && tr == r) {
return t[v];
}
push(v);
int tm = tl + tr >> 1;
return max(get(v << 1, tl, tm, l, min(tm, r)),
get(v << 1 | 1, tm + 1, tr, max(tm + 1, l), r));
}
};
int n, m;
int lf[N], rf[N];
ll a[N];
ll dp[N];
vi st[N], fin[N];
void smain() {
cin >> n >> m;
fori(i, m) {
cin >> lf[i] >> rf[i] >> a[i];
st[lf[i]].push_back(i);
fin[lf[i]].push_back(i);
}
SegmentTree tree;
for (int i = 1; i <= n; ++i) {
for (auto ind : st[i]) {
tree.upd(1, 0, n, 0, i - 1, a[ind]);
}
dp[i] = tree.get(1, 0, n, 0, i - 1);
tree.upd(1, 0, n, i, i, dp[i]);
for (auto ind : fin[i]) {
tree.upd(1, 0, n, 0, lf[ind] - 1, -a[ind]);
}
// cout << "dp[" << i << "] = " << dp[i] << endl;
}
cout << *max_element(dp, dp + n + 1);
} | #include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
//#define int ll
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;
typedef complex<double> base;
#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define mp(a, b) make_pair(a, b)
#define modsum(a, b) ((a) + (b) >= M ? (a) + (b)-M : (a) + (b))
#define modsubtract(a, b) ((a) - (b) < 0 ? (a) - (b) + M : (a) - (b))
#define modmultiply(a, b) (((a) * (b)) % M)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for (int i = 0; i < int(n); ++i)
#define cint const int &
#define SZ(a) ((int)((a).size()))
#define watch(x) cout << (#x) << " = " << (x) << endl;
const double PI = 2 * acos(0.0);
const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";
template <class T> inline ostream &operator<<(ostream &out, vector<T> &a) {
out << "{";
fori(i, SZ(a)) out << a[i] << vector<string>{", ", "}"}[i + 1 == SZ(a)];
return out;
}
void smain();
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifdef MAX_HOME
freopen("input.txt", "r", stdin);
clock_t start = clock();
#define cerr cout
#endif
cout << setprecision(12) << fixed;
smain();
#ifdef MAX_HOME
cout << "\n\n\n\n";
cout << "TOTAL EXECUTION TIME: " << float(clock() - start) / CLOCKS_PER_SEC
<< endl;
#endif
}
const int N = 2e5 + 9;
const ll oo = 1e18;
ll t[N << 2];
ll pushing[N << 2];
struct SegmentTree {
SegmentTree() {
fill(t, t + (N << 2), 0);
fill(pushing, pushing + (N << 2), 0);
}
void push(int v) {
pushing[v << 1] += pushing[v];
t[v << 1] += pushing[v];
pushing[v << 1 | 1] += pushing[v];
t[v << 1 | 1] += pushing[v];
pushing[v] = 0;
}
void upd(int v, int tl, int tr, int l, int r, ll inc) {
if (l > r)
return;
if (tl == l && tr == r) {
t[v] += inc;
pushing[v] += inc;
return;
}
push(v);
int tm = tl + tr >> 1;
upd(v << 1, tl, tm, l, min(tm, r), inc);
upd(v << 1 | 1, tm + 1, tr, max(tm + 1, l), r, inc);
t[v] = max(t[v << 1], t[v << 1 | 1]);
}
ll get(int v, int tl, int tr, int l, int r) {
if (l > r)
return -oo;
if (tl == l && tr == r) {
return t[v];
}
push(v);
int tm = tl + tr >> 1;
return max(get(v << 1, tl, tm, l, min(tm, r)),
get(v << 1 | 1, tm + 1, tr, max(tm + 1, l), r));
}
};
int n, m;
int lf[N], rf[N];
ll a[N];
ll dp[N];
vi st[N], fin[N];
void smain() {
cin >> n >> m;
fori(i, m) {
cin >> lf[i] >> rf[i] >> a[i];
st[lf[i]].push_back(i);
fin[rf[i]].push_back(i);
}
SegmentTree tree;
for (int i = 1; i <= n; ++i) {
for (auto ind : st[i]) {
tree.upd(1, 0, n, 0, i - 1, a[ind]);
}
dp[i] = tree.get(1, 0, n, 0, i - 1);
tree.upd(1, 0, n, i, i, dp[i]);
for (auto ind : fin[i]) {
tree.upd(1, 0, n, 0, lf[ind] - 1, -a[ind]);
}
// cout << "dp[" << i << "] = " << dp[i] << endl;
}
cout << *max_element(dp, dp + n + 1);
} | [
"identifier.change",
"variable_access.subscript.index.change"
] | 986,753 | 986,754 | u443685186 | cpp |
p03182 | #include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T> ostream &operator<<(ostream &os, const V<T> &v) {
os << "[";
for (auto d : v)
os << d << ", ";
return os << "]";
}
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
return os << "P(" << p.first << ", " << p.second << ")";
}
template <class D, class Op> struct SimpleSeg {
D e;
Op op;
int sz, lg; //(2^lgに拡張後の)サイズ, lg
V<D> d;
SimpleSeg(const V<D> &v, D _e, Op _op) : e(_e), op(_op) {
int n = int(v.size());
lg = 1;
while ((1 << lg) < n)
lg++;
sz = 1 << lg;
d = V<D>(2 * sz, e);
for (int i = 0; i < n; i++)
d[sz + i] = v[i];
for (int i = sz - 1; i >= 0; i--) {
update(i);
}
}
void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }
void set(int p, D x) {
p += sz;
d[p] = x;
for (int i = 1; i <= lg; i++)
update(p >> i);
}
D single(int p) { return d[p + sz]; }
D sum(int a, int b, int l, int r, int k) {
if (b <= l || r <= a)
return e;
if (a <= l && r <= b)
return d[k];
int mid = (l + r) / 2;
return op(sum(a, b, l, mid, 2 * k), sum(a, b, mid, r, 2 * k + 1));
}
D sum(int a, int b) { return sum(a, b, 0, sz, 1); }
};
template <class D, class Op>
SimpleSeg<D, Op> get_simple_seg(V<D> v, D e, Op op) {
return SimpleSeg<D, Op>(v, e, op);
}
template <class D, class L, class OpDD, class OpDL, class OpLL> struct SegTree {
D e_d;
L e_l;
OpDD op_dd;
OpDL op_dl;
OpLL op_ll;
int sz, lg; //(2^lgに拡張後の)サイズ, lg
V<D> d;
V<L> lz;
SegTree(const V<D> &v, D _e_d, L _e_l, OpDD _op_dd, OpDL _op_dl, OpLL _op_ll)
: e_d(_e_d), e_l(_e_l), op_dd(_op_dd), op_dl(_op_dl), op_ll(_op_ll) {
int n = int(v.size());
lg = 1;
while ((1 << lg) < n)
lg++;
sz = 1 << lg;
d = V<D>(2 * sz, e_d);
lz = V<L>(2 * sz, e_l);
for (int i = 0; i < n; i++)
d[sz + i] = v[i];
for (int i = sz - 1; i >= 0; i--) {
update(i);
}
}
void all_add(int k, L x) {
d[k] = op_dl(d[k], x);
lz[k] = op_ll(lz[k], x);
}
void push(int k) {
all_add(2 * k, lz[k]);
all_add(2 * k + 1, lz[k]);
lz[k] = e_l;
}
void update(int k) { d[k] = op_dd(d[2 * k], d[2 * k + 1]); }
void set(int p, D x) {
p += sz;
for (int i = lg; i >= 1; i--)
push(p >> i);
d[p] = x;
for (int i = 1; i <= lg; i++)
update(p >> i);
}
void add(int a, int b, L x, int l, int r, int k) {
if (b <= l || r <= a)
return;
if (a <= l && r <= b) {
all_add(k, x);
return;
}
push(k);
int mid = (l + r) / 2;
add(a, b, x, l, mid, 2 * k);
add(a, b, x, mid, r, 2 * k + 1);
update(k);
}
void add(int a, int b, L x) { add(a, b, x, 0, sz, 1); }
D single(int p) {
p += sz;
for (int i = lg; i >= 1; i--)
push(p >> i);
return d[p];
}
D sum(int a, int b, int l, int r, int k) {
if (b <= l || r <= a)
return e_d;
if (a <= l && r <= b)
return d[k];
push(k);
int mid = (l + r) / 2;
return op_dd(sum(a, b, l, mid, 2 * k), sum(a, b, mid, r, 2 * k + 1));
}
D sum(int a, int b) { return sum(a, b, 0, sz, 1); }
};
template <class D, class L, class OpDD, class OpDL, class OpLL>
SegTree<D, L, OpDD, OpDL, OpLL> get_seg(V<D> v, D e_d, L e_l, OpDD op_dd,
OpDL op_dl, OpLL op_ll) {
return SegTree<D, L, OpDD, OpDL, OpLL>(v, e_d, e_l, op_dd, op_dl, op_ll);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
struct Q {
int l;
ll a;
};
int n, m;
cin >> n >> m;
VV<Q> que(n + 1);
ll ans = 0;
for (int i = 0; i < m; i++) {
int l, r, a;
cin >> l >> r >> a;
l--;
ans += a;
que[r].push_back(Q{l, -a});
}
auto seg = get_seg(
V<ll>(n + 1, 0), 0LL, 0LL, [&](ll a, ll b) { return max(a, b); },
[&](ll a, ll b) { return a + b; }, [&](ll a, ll b) { return a + b; });
for (int i = 1; i <= n; i++) {
seg.set(i, seg.sum(0, i));
for (auto q : que[i]) {
seg.add(0, q.l + 1, q.a);
}
}
cout << ans + seg.sum(0, n) << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T> ostream &operator<<(ostream &os, const V<T> &v) {
os << "[";
for (auto d : v)
os << d << ", ";
return os << "]";
}
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
return os << "P(" << p.first << ", " << p.second << ")";
}
template <class D, class Op> struct SimpleSeg {
D e;
Op op;
int sz, lg; //(2^lgに拡張後の)サイズ, lg
V<D> d;
SimpleSeg(const V<D> &v, D _e, Op _op) : e(_e), op(_op) {
int n = int(v.size());
lg = 1;
while ((1 << lg) < n)
lg++;
sz = 1 << lg;
d = V<D>(2 * sz, e);
for (int i = 0; i < n; i++)
d[sz + i] = v[i];
for (int i = sz - 1; i >= 0; i--) {
update(i);
}
}
void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }
void set(int p, D x) {
p += sz;
d[p] = x;
for (int i = 1; i <= lg; i++)
update(p >> i);
}
D single(int p) { return d[p + sz]; }
D sum(int a, int b, int l, int r, int k) {
if (b <= l || r <= a)
return e;
if (a <= l && r <= b)
return d[k];
int mid = (l + r) / 2;
return op(sum(a, b, l, mid, 2 * k), sum(a, b, mid, r, 2 * k + 1));
}
D sum(int a, int b) { return sum(a, b, 0, sz, 1); }
};
template <class D, class Op>
SimpleSeg<D, Op> get_simple_seg(V<D> v, D e, Op op) {
return SimpleSeg<D, Op>(v, e, op);
}
template <class D, class L, class OpDD, class OpDL, class OpLL> struct SegTree {
D e_d;
L e_l;
OpDD op_dd;
OpDL op_dl;
OpLL op_ll;
int sz, lg; //(2^lgに拡張後の)サイズ, lg
V<D> d;
V<L> lz;
SegTree(const V<D> &v, D _e_d, L _e_l, OpDD _op_dd, OpDL _op_dl, OpLL _op_ll)
: e_d(_e_d), e_l(_e_l), op_dd(_op_dd), op_dl(_op_dl), op_ll(_op_ll) {
int n = int(v.size());
lg = 1;
while ((1 << lg) < n)
lg++;
sz = 1 << lg;
d = V<D>(2 * sz, e_d);
lz = V<L>(2 * sz, e_l);
for (int i = 0; i < n; i++)
d[sz + i] = v[i];
for (int i = sz - 1; i >= 0; i--) {
update(i);
}
}
void all_add(int k, L x) {
d[k] = op_dl(d[k], x);
lz[k] = op_ll(lz[k], x);
}
void push(int k) {
all_add(2 * k, lz[k]);
all_add(2 * k + 1, lz[k]);
lz[k] = e_l;
}
void update(int k) { d[k] = op_dd(d[2 * k], d[2 * k + 1]); }
void set(int p, D x) {
p += sz;
for (int i = lg; i >= 1; i--)
push(p >> i);
d[p] = x;
for (int i = 1; i <= lg; i++)
update(p >> i);
}
void add(int a, int b, L x, int l, int r, int k) {
if (b <= l || r <= a)
return;
if (a <= l && r <= b) {
all_add(k, x);
return;
}
push(k);
int mid = (l + r) / 2;
add(a, b, x, l, mid, 2 * k);
add(a, b, x, mid, r, 2 * k + 1);
update(k);
}
void add(int a, int b, L x) { add(a, b, x, 0, sz, 1); }
D single(int p) {
p += sz;
for (int i = lg; i >= 1; i--)
push(p >> i);
return d[p];
}
D sum(int a, int b, int l, int r, int k) {
if (b <= l || r <= a)
return e_d;
if (a <= l && r <= b)
return d[k];
push(k);
int mid = (l + r) / 2;
return op_dd(sum(a, b, l, mid, 2 * k), sum(a, b, mid, r, 2 * k + 1));
}
D sum(int a, int b) { return sum(a, b, 0, sz, 1); }
};
template <class D, class L, class OpDD, class OpDL, class OpLL>
SegTree<D, L, OpDD, OpDL, OpLL> get_seg(V<D> v, D e_d, L e_l, OpDD op_dd,
OpDL op_dl, OpLL op_ll) {
return SegTree<D, L, OpDD, OpDL, OpLL>(v, e_d, e_l, op_dd, op_dl, op_ll);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
struct Q {
int l;
ll a;
};
int n, m;
cin >> n >> m;
VV<Q> que(n + 1);
ll ans = 0;
for (int i = 0; i < m; i++) {
int l, r, a;
cin >> l >> r >> a;
l--;
ans += a;
que[r].push_back(Q{l, -a});
}
auto seg = get_seg(
V<ll>(n + 1, 0), 0LL, 0LL, [&](ll a, ll b) { return max(a, b); },
[&](ll a, ll b) { return a + b; }, [&](ll a, ll b) { return a + b; });
for (int i = 1; i <= n; i++) {
seg.set(i, seg.sum(0, i));
for (auto q : que[i]) {
seg.add(0, q.l + 1, q.a);
}
}
cout << ans + seg.sum(0, n + 1) << endl;
return 0;
}
| [
"expression.operation.binary.add"
] | 986,757 | 986,758 | u965174248 | cpp |
p03182 | #include <algorithm>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int N, M;
vector<pair<int, int>> intv[200200];
const int Z = 1 << 18;
struct node {
node() { sum = mx = 0; }
node(int x) {
sum = mx = x;
if (mx < 0)
mx = 0;
}
long long sum, mx;
node operator+(node t) {
node r(0);
r.sum = sum + t.sum;
r.mx = mx;
if (r.mx < sum + t.mx)
r.mx = sum + t.mx;
return r;
}
} IT[Z * 2];
node out(int x, int y) {
x += Z;
y += Z;
node l, r;
while (x < y) {
if (x & 1)
l = l + IT[x++];
if (~y & 1)
r = IT[y--] + r;
x /= 2;
y /= 2;
}
if (x == y)
l = l + IT[x];
return l + r;
}
void in(int x, long long p) {
x += Z;
p += IT[x].sum;
IT[x] = node(p);
x /= 2;
while (x) {
IT[x] = IT[x * 2] + IT[x * 2 + 1];
x /= 2;
}
}
int main() {
scanf("%d %d", &N, &M);
for (int i = 0; i < M; i++) {
int l, r, a;
scanf("%d %d %d", &l, &r, &a);
intv[r].push_back({l, a});
}
for (int i = 1; i <= N; i++) {
auto r = out(0, i - 1);
in(i, r.mx);
in(i + 1, -r.mx);
for (auto &p : intv[i]) {
in(p.first, p.second);
in(i + 1, -p.second);
}
}
printf("%lld\n", out(0, N).mx);
return 0;
}
| #include <algorithm>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int N, M;
vector<pair<int, int>> intv[200200];
const int Z = 1 << 18;
struct node {
node() { sum = mx = 0; }
node(long long x) {
sum = mx = x;
if (mx < 0)
mx = 0;
}
long long sum, mx;
node operator+(node t) {
node r(0);
r.sum = sum + t.sum;
r.mx = mx;
if (r.mx < sum + t.mx)
r.mx = sum + t.mx;
return r;
}
} IT[Z * 2];
node out(int x, int y) {
x += Z;
y += Z;
node l, r;
while (x < y) {
if (x & 1)
l = l + IT[x++];
if (~y & 1)
r = IT[y--] + r;
x /= 2;
y /= 2;
}
if (x == y)
l = l + IT[x];
return l + r;
}
void in(int x, long long p) {
x += Z;
p += IT[x].sum;
IT[x] = node(p);
x /= 2;
while (x) {
IT[x] = IT[x * 2] + IT[x * 2 + 1];
x /= 2;
}
}
int main() {
scanf("%d %d", &N, &M);
for (int i = 0; i < M; i++) {
int l, r, a;
scanf("%d %d %d", &l, &r, &a);
intv[r].push_back({l, a});
}
for (int i = 1; i <= N; i++) {
auto r = out(0, i - 1);
in(i, r.mx);
in(i + 1, -r.mx);
for (auto &p : intv[i]) {
in(p.first, p.second);
in(i + 1, -p.second);
}
}
printf("%lld\n", out(0, N).mx);
return 0;
}
| [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 986,759 | 986,760 | u233632872 | cpp |
p03183 | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
// State
// dp[i][j]: The maximum value we can get by using blocks from
// 0...i and sum of blocks in the tower = j
// Initialization
// dp[0][W[0]] = V[0]
// Transitions
// dp[i][j] = max(V[j]+dp[i-W[0]][j-1], dp[i][j-1])
// Order of evaluation
// Rowise or Columnwise
// Answer: argmax(dp[0...W_max][N])
struct B {
long long w;
long long s;
long long v;
};
vector<vector<long long>> dp(10004, vector<long long>(1004, 0));
bool compare(B b1, B b2) { return (b1.w + b1.s <= b2.w + b2.s); }
int main() {
long long N;
cin >> N;
vector<B> boxes(N);
for (long long i = 0; i < N; i++) {
long long w, s, v;
cin >> w >> s >> v;
boxes[i].w = w;
boxes[i].s = s;
boxes[i].v = v;
}
sort(boxes.begin(), boxes.end(), compare);
long long W_max = 20004;
dp[boxes[0].w][0] = boxes[0].v;
for (int i = 0; i < W_max; i++) {
if (i >= boxes[0].w) {
dp[i][0] = boxes[0].v;
}
}
for (long long j = 1; j < N; j++) {
for (long long i = 0; i < W_max; i++) {
if (i - boxes[j].w >= 0 && boxes[j].s + boxes[j].w - i >= 0) {
dp[i][j] = max(dp[i - boxes[j].w][j - 1] + boxes[j].v, dp[i][j - 1]);
} else {
dp[i][j] = dp[i][j - 1];
}
}
}
long long result = 0;
for (long long i = 0; i < W_max; i++) {
if (result < dp[i][N - 1])
result = dp[i][N - 1];
}
cout << result << endl;
}
| #include <bits/stdc++.h>
#include <iostream>
using namespace std;
// State
// dp[i][j]: The maximum value we can get by using blocks from
// 0...i and sum of blocks in the tower = j
// Initialization
// dp[0][W[0]] = V[0]
// Transitions
// dp[i][j] = max(V[j]+dp[i-W[0]][j-1], dp[i][j-1])
// Order of evaluation
// Rowise or Columnwise
// Answer: argmax(dp[0...W_max][N])
struct B {
long long w;
long long s;
long long v;
};
vector<vector<long long>> dp(20004, vector<long long>(1004, 0));
bool compare(B b1, B b2) { return (b1.w + b1.s <= b2.w + b2.s); }
int main() {
long long N;
cin >> N;
vector<B> boxes(N);
for (long long i = 0; i < N; i++) {
long long w, s, v;
cin >> w >> s >> v;
boxes[i].w = w;
boxes[i].s = s;
boxes[i].v = v;
}
sort(boxes.begin(), boxes.end(), compare);
long long W_max = 20004;
dp[boxes[0].w][0] = boxes[0].v;
for (int i = 0; i < W_max; i++) {
if (i >= boxes[0].w) {
dp[i][0] = boxes[0].v;
}
}
for (long long j = 1; j < N; j++) {
for (long long i = 0; i < W_max; i++) {
if (i - boxes[j].w >= 0 && boxes[j].s + boxes[j].w - i >= 0) {
dp[i][j] = max(dp[i - boxes[j].w][j - 1] + boxes[j].v, dp[i][j - 1]);
} else {
dp[i][j] = dp[i][j - 1];
}
}
}
long long result = 0;
for (long long i = 0; i < W_max; i++) {
if (result < dp[i][N - 1])
result = dp[i][N - 1];
}
cout << result << endl;
}
| [
"literal.number.change",
"call.arguments.change"
] | 986,766 | 986,767 | u463134004 | cpp |
p03183 | #include <bits/stdc++.h>
#define F first
#define S second
#define sq(x) (x) * (x)
using namespace std;
typedef long long LL;
typedef pair<LL, LL> pii;
const LL INF = 0x3f3f3f3f3f3f3f3fLL;
const LL MOD = 1e9 + 7;
struct B {
int w, s, v;
bool operator<(const B &rhs) const { return w + s < rhs.w + rhs.s; }
};
void marmot0814() {
int n;
cin >> n;
vector<B> arr(n);
for (auto &p : arr)
cin >> p.w >> p.s >> p.v;
sort(arr.begin(), arr.end());
vector<LL> dp(1e4 + 5, 0);
dp[0] = 0;
for (int i = 0; i < n; i++)
for (int w = arr[i].s; w >= 0; w--)
dp[w + arr[i].w] = max(dp[w + arr[i].w], dp[w] + arr[i].v);
cout << *max_element(dp.begin(), dp.end()) << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t = 1, kase = 0; // cin >> t;
while (t--) {
// cout << "Case #" << ++kase << ":";
marmot0814();
}
} | #include <bits/stdc++.h>
#define F first
#define S second
#define sq(x) (x) * (x)
using namespace std;
typedef long long LL;
typedef pair<LL, LL> pii;
const LL INF = 0x3f3f3f3f3f3f3f3fLL;
const LL MOD = 1e9 + 7;
struct B {
int w, s;
LL v;
bool operator<(const B &rhs) const { return w + s < rhs.w + rhs.s; }
};
void marmot0814() {
int n;
cin >> n;
vector<B> arr(n);
for (auto &p : arr)
cin >> p.w >> p.s >> p.v;
sort(arr.begin(), arr.end());
vector<LL> dp(2e4 + 5, 0);
dp[0] = 0;
for (int i = 0; i < n; i++)
for (int w = arr[i].s; w >= 0; w--)
dp[w + arr[i].w] = max(dp[w + arr[i].w], dp[w] + arr[i].v);
cout << *max_element(dp.begin(), dp.end()) << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t = 1, kase = 0; // cin >> t;
while (t--) {
// cout << "Case #" << ++kase << ":";
marmot0814();
}
} | [
"literal.number.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 986,807 | 986,808 | u194917097 | cpp |
p03183 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> l_l;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<l_l> vpl;
typedef vector<string> vs;
typedef pair<l_l, ll> lll;
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = 1; i <= (n); i++)
const int INF = 1001001000;
const int mINF = -1001001000;
const ll LINF = 10100100100100100;
const ll dx[4] = {1, -1, 0, 0};
const ll dy[4] = {0, 0, 1, -1};
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
ll n;
ll w[1100], s[1100], v[1100];
ll dp[1100][220000];
int main() {
cin >> n;
rep(i, n) cin >> w[i] >> s[i] >> v[i];
vl block;
rep(i, n) block.pb(i);
sort(block.begin(), block.end(),
[&](int x, int y) { return s[x] + w[x] < s[y] + w[y]; });
for (int i = 1; i <= n; i++) {
ll ind = block[i - 1];
for (int j = 0; j < 220000; j++) {
dp[i][j] = dp[i - 1][j];
if (j - w[ind] <= s[ind] && j - w[ind] >= 0) {
dp[i][j] = max(dp[i][j], dp[i - 1][j - w[ind]] + v[ind]);
}
}
}
ll ans = 0;
rep(i, 220000) chmax(ans, dp[n][i]);
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> l_l;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<l_l> vpl;
typedef vector<string> vs;
typedef pair<l_l, ll> lll;
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = 1; i <= (n); i++)
const int INF = 1001001000;
const int mINF = -1001001000;
const ll LINF = 10100100100100100;
const ll dx[4] = {1, -1, 0, 0};
const ll dy[4] = {0, 0, 1, -1};
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
ll n;
ll w[1100], s[1100], v[1100];
ll dp[1100][22000];
int main() {
cin >> n;
rep(i, n) cin >> w[i] >> s[i] >> v[i];
vl block;
rep(i, n) block.pb(i);
sort(block.begin(), block.end(),
[&](int x, int y) { return s[x] + w[x] < s[y] + w[y]; });
for (int i = 1; i <= n; i++) {
ll ind = block[i - 1];
for (int j = 0; j < 220000; j++) {
dp[i][j] = dp[i - 1][j];
if (j - w[ind] <= s[ind] && j - w[ind] >= 0) {
dp[i][j] = max(dp[i][j], dp[i - 1][j - w[ind]] + v[ind]);
}
}
}
ll ans = 0;
rep(i, 220000) chmax(ans, dp[n][i]);
cout << ans << endl;
return 0;
} | [
"literal.number.change",
"variable_declaration.array_dimensions.change"
] | 986,841 | 986,842 | u796877631 | cpp |
p03183 | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll, ll>
#define iii pair<ii, ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl;
#define rep(x, start, end) \
for (auto x = (start) - ((start) > (end)); x != (end) - ((start) > (end)); \
((start) < (end) ? x++ : x--))
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
ll MAX(ll a) { return a; }
ll MIN(ll a) { return a; }
template <typename... Args> ll MAX(ll a, Args... args) {
return max(a, MAX(args...));
}
template <typename... Args> ll MIN(ll a, Args... args) {
return min(a, MIN(args...));
}
#define indexed_set \
tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
const ll INF = 1e18;
int n;
vector<iii> val;
ll memo[10005];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
int a, b, c;
rep(x, 0, n) {
cin >> a >> b >> c;
val.push_back(iii(ii(a, b), c));
}
sort(all(val), [](iii &i, iii &j) {
if (i.fi.fi + i.fi.se == j.fi.fi + j.fi.se)
return i.fi.fi < j.fi.fi;
else
return i.fi.fi + i.fi.se < j.fi.fi + j.fi.se;
});
rep(x, 1, 10005) memo[x] = -INF;
for (auto &it : val) {
// cout<<it.fi.fi<<" "<<it.fi.se<<" "<<it.se<<endl;
rep(x, min(it.fi.se + 1, 100005 - it.fi.fi), 0) {
memo[x + it.fi.fi] = max(memo[x + it.fi.fi], memo[x] + it.se);
// cout<<x+it.fi.fi<<" "<<memo[x]+it.se<<endl;
}
}
ll ans = 0;
rep(x, 0, 10005) ans = max(ans, memo[x]);
cout << ans << endl;
}
| #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll, ll>
#define iii pair<ii, ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl;
#define rep(x, start, end) \
for (auto x = (start) - ((start) > (end)); x != (end) - ((start) > (end)); \
((start) < (end) ? x++ : x--))
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
ll MAX(ll a) { return a; }
ll MIN(ll a) { return a; }
template <typename... Args> ll MAX(ll a, Args... args) {
return max(a, MAX(args...));
}
template <typename... Args> ll MIN(ll a, Args... args) {
return min(a, MIN(args...));
}
#define indexed_set \
tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
const ll INF = 1e18;
int n;
vector<iii> val;
ll memo[20005];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
int a, b, c;
rep(x, 0, n) {
cin >> a >> b >> c;
val.push_back(iii(ii(a, b), c));
}
sort(all(val), [](iii &i, iii &j) {
if (i.fi.fi + i.fi.se == j.fi.fi + j.fi.se)
return i.fi.fi < j.fi.fi;
else
return i.fi.fi + i.fi.se < j.fi.fi + j.fi.se;
});
rep(x, 1, 20005) memo[x] = -INF;
for (auto &it : val) {
// cout<<it.fi.fi<<" "<<it.fi.se<<" "<<it.se<<endl;
rep(x, min(it.fi.se + 1, 20005 - it.fi.fi), 0) {
memo[x + it.fi.fi] = max(memo[x + it.fi.fi], memo[x] + it.se);
// cout<<x+it.fi.fi<<" "<<memo[x]+it.se<<endl;
}
}
ll ans = 0;
rep(x, 0, 20005) ans = max(ans, memo[x]);
cout << ans << endl;
}
| [
"literal.number.change",
"variable_declaration.array_dimensions.change",
"assignment.variable.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 986,895 | 986,894 | u780811667 | cpp |
p03183 | #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1 << 30) - 1)
#define LINF (1LL << 60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;
const int N = 1000006;
//////////////////////////////
struct Block {
Int w, s, v;
bool operator<(const Block &a) const { return w + s < a.w + a.s; }
} Blocks[1003];
int n;
Int dp[1003][22000];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); // fflush(stdout);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> Blocks[i].w >> Blocks[i].s >> Blocks[i].v;
}
sort(Blocks, Blocks + n);
for (int i = 1; i <= n; i++) {
for (int j = 0; j < 22000; j++) {
dp[i][j] = dp[i - 1][j];
if (j - Blocks[i].w >= 0 && j - Blocks[i].w <= Blocks[i].s) {
dp[i][j] = max(dp[i][j], dp[i - 1][j - Blocks[i].w] + j - Blocks[i].v);
}
}
}
Int ans = 0;
for (int j = 0; j < 22000; j++) {
ans = max(ans, dp[n][j]);
}
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1 << 30) - 1)
#define LINF (1LL << 60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;
const int N = 1000006;
//////////////////////////////
struct Block {
Int w, s, v;
bool operator<(const Block &a) const { return w + s < a.w + a.s; }
} Blocks[1003];
int n;
Int dp[1003][22000];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); // fflush(stdout);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> Blocks[i].w >> Blocks[i].s >> Blocks[i].v;
}
sort(Blocks, Blocks + n + 1);
for (int i = 1; i <= n; i++) {
for (int j = 0; j < 22000; j++) {
dp[i][j] = dp[i - 1][j];
if (j - Blocks[i].w >= 0 && j - Blocks[i].w <= Blocks[i].s) {
dp[i][j] = max(dp[i][j], dp[i - 1][j - Blocks[i].w] + Blocks[i].v);
}
}
}
Int ans = 0;
for (int j = 0; j < 22000; j++) {
ans = max(ans, dp[n][j]);
}
cout << ans << endl;
return 0;
}
| [
"expression.operation.binary.remove"
] | 986,900 | 986,901 | u089869622 | cpp |
p03183 | #include <bits/stdc++.h>
// ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
// clock_t start=clock();clock_t
// end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;
typedef pair<pii, int> ppii;
typedef pair<int, pii> pipi;
typedef pair<ll, ll> pll;
typedef pair<pll, ll> ppll;
typedef pair<ll, pll> plpl;
typedef pair<pii, pii> P;
typedef tuple<ll, ll, ll> tl;
typedef pair<double, double> pdd;
typedef vector<vector<ll>> mat;
ll mod = 1000000007;
ll mod2 = 998244353;
ll mod3 = 1000003;
ll mod4 = 998244853;
ll mod5 = 1000000009;
ll inf = 1LL << 62;
int iinf = 1 << 30;
double pi = 3.141592653589793238462643383279L;
double eps = 1e-14;
#define rep(i, m, n) for (ll i = m; i < n; i++)
#define rrep(i, n, m) for (ll i = n; i >= m; i--)
#define srep(itr, st) for (auto itr = st.begin(); itr != st.end(); itr++)
#define mrep(itr, mp) for (auto &itr : mp)
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
int dh[4] = {1, -1, 0, 0};
int dw[4] = {0, 0, 1, -1};
int ddh[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int ddw[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM =
chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
#define umh unordered_map<ll, ll, custom_hash>
ll gcd(ll a, ll b) {
if (a < b)
swap(a, b);
if (b == 0)
return a;
if (a % b == 0)
return b;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
ll c = gcd(a, b);
return a * b / c;
}
ll Pow(ll n, ll k) {
ll ret = 1;
ll now = n;
while (k > 0) {
if (k & 1)
ret *= now;
now *= now;
k /= 2;
}
return ret;
}
ll beki(ll n, ll k, ll md) {
ll ret = 1;
ll now = n;
now %= md;
while (k > 0) {
if (k % 2 == 1) {
ret *= now;
ret %= md;
}
now *= now;
now %= md;
k /= 2;
}
return ret;
}
ll gyaku(ll n, ll md) { return beki(n, md - 2, md); }
ll poc(ll n) {
ll ret = 0;
ll u = n;
while (u > 0) {
ret += u % 2;
u /= 2;
}
return ret;
}
bool cmp(ppll a, ppll b) {
return a.first.first + a.first.second < b.first.first + b.first.second;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll n;
cin >> n;
vector<ppll> v;
rep(i, 0, n) {
ll w, s, vv;
cin >> w >> s >> vv;
v.push_back({{s, w}, vv});
}
sort(v.begin(), v.end(), cmp);
ll dp[11001];
fill(dp, dp + 10001, -inf);
dp[0] = 0;
rep(i, 0, n) {
ll s = v[i].first.first, w = v[i].first.second, co = v[i].second;
rrep(j, s, 0) {
ll ne = j + w;
if (ne <= 11000)
Max(dp[ne], dp[j] + co);
}
}
ll ans = 0;
rep(i, 0, 11001) Max(ans, dp[i]);
cout << ans << endl;
}
| #include <bits/stdc++.h>
// ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
// clock_t start=clock();clock_t
// end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;
typedef pair<pii, int> ppii;
typedef pair<int, pii> pipi;
typedef pair<ll, ll> pll;
typedef pair<pll, ll> ppll;
typedef pair<ll, pll> plpl;
typedef pair<pii, pii> P;
typedef tuple<ll, ll, ll> tl;
typedef pair<double, double> pdd;
typedef vector<vector<ll>> mat;
ll mod = 1000000007;
ll mod2 = 998244353;
ll mod3 = 1000003;
ll mod4 = 998244853;
ll mod5 = 1000000009;
ll inf = 1LL << 62;
int iinf = 1 << 30;
double pi = 3.141592653589793238462643383279L;
double eps = 1e-14;
#define rep(i, m, n) for (ll i = m; i < n; i++)
#define rrep(i, n, m) for (ll i = n; i >= m; i--)
#define srep(itr, st) for (auto itr = st.begin(); itr != st.end(); itr++)
#define mrep(itr, mp) for (auto &itr : mp)
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
int dh[4] = {1, -1, 0, 0};
int dw[4] = {0, 0, 1, -1};
int ddh[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int ddw[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM =
chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
#define umh unordered_map<ll, ll, custom_hash>
ll gcd(ll a, ll b) {
if (a < b)
swap(a, b);
if (b == 0)
return a;
if (a % b == 0)
return b;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
ll c = gcd(a, b);
return a * b / c;
}
ll Pow(ll n, ll k) {
ll ret = 1;
ll now = n;
while (k > 0) {
if (k & 1)
ret *= now;
now *= now;
k /= 2;
}
return ret;
}
ll beki(ll n, ll k, ll md) {
ll ret = 1;
ll now = n;
now %= md;
while (k > 0) {
if (k % 2 == 1) {
ret *= now;
ret %= md;
}
now *= now;
now %= md;
k /= 2;
}
return ret;
}
ll gyaku(ll n, ll md) { return beki(n, md - 2, md); }
ll poc(ll n) {
ll ret = 0;
ll u = n;
while (u > 0) {
ret += u % 2;
u /= 2;
}
return ret;
}
bool cmp(ppll a, ppll b) {
return a.first.first + a.first.second < b.first.first + b.first.second;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll n;
cin >> n;
vector<ppll> v;
rep(i, 0, n) {
ll w, s, vv;
cin >> w >> s >> vv;
v.push_back({{s, w}, vv});
}
sort(v.begin(), v.end(), cmp);
ll dp[20001];
fill(dp, dp + 20001, -inf);
dp[0] = 0;
rep(i, 0, n) {
ll s = v[i].first.first, w = v[i].first.second, co = v[i].second;
rrep(j, s, 0) {
ll ne = j + w;
if (ne <= 20000)
Max(dp[ne], dp[j] + co);
}
}
ll ans = 0;
rep(i, 0, 20001) Max(ans, dp[i]);
cout << ans << endl;
}
| [
"literal.number.change",
"variable_declaration.array_dimensions.change",
"call.arguments.change",
"expression.operation.binary.change",
"control_flow.branch.if.condition.change"
] | 986,907 | 986,906 | u357265888 | cpp |
p03183 | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007
#include <string.h>
#define inf 9000000000000000000
#define maxn 200006
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;
#define endl '\n'
#define mapint_iterator map<int, int>::iterator
#define mapll_iterator map<ll, ll>::iterator
#define setint_iterator set<int>::iterator
#define setll_iterator set<ll>::iterator
#define setpint_iterator set<pint>::iterator
#define setpll_iterator set<pll>::iterator
#define trace(x) cout << #x << ": " << x << " " << endl
#define trace2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z) \
cout << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << endl
#define trace4(a, b, c, d) \
cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << endl
#define cout1(a) cout << a << endl
#define cout2(a, b) cout << a << ' ' << b << endl
#define cout3(a, b, c) cout << a << " " << b << " " << c << endl
#define cout4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
#define vcout(v, i) cout << v[i].fi << " " << v[i].se << endl
typedef priority_queue<ll, vector<ll>, greater<ll>> pqset;
typedef priority_queue<pint, vector<pint>, greater<pint>> pqset_ll;
#define pb push_back
#define fi first
#define se second
#include <ext/pb_ds/assoc_container.hpp>
ll dxk[] = {0, 0, 1, -1, 1, 1, -1, -1};
ll dyk[] = {1, -1, 0, 0, 1, -1, 1, -1};
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
os;
typedef tree<pll, null_type, less<pll>, rb_tree_tag,
tree_order_statistics_node_update>
os_pair;
#define acc (ios::sync_with_stdio(false), cin.tie(0))
#define rep(i, n) for (ll i = 0; i < n; i++)
#define per(i, n) for (ll i = n - 1; i >= 0; i--)
#define rep1(i, n) for (ll i = 1; i <= n; i++)
#define per1(i, n) for (ll i = n; i > 0; i--)
#define repeat(i, start, n) for (ll i = start; i < n; i++)
#define print(a, n) \
for (ll i = 0; i < n; i++) { \
cout << a[i] << " "; \
}
ll ll_max(ll a, ll b, ll c) { return max(a, max(b, c)); }
int int_max(int a, int b, int c) { return max(a, max(b, c)); }
ll ll_min(ll a, ll b, ll c) { return min(a, min(b, c)); }
int int_min(int a, int b, int c) { return min(a, min(b, c)); }
ll max(int a, ll b) { return max((ll)a, b); }
ll min(int a, ll b) { return min((ll)a, b); }
ll min(ll a, int b) { return min(a, (ll)b); }
ll max(ll a, int b) { return max(a, (ll)b); }
ll dx[] = {0, 0, 1, -1};
ll dy[] = {1, -1, 0, 0};
ll power(ll a, ll b) {
if (a == 1)
return 1;
if (b == 0)
return 1;
ll c = power(a, b / 2);
ll res = 1;
if (b % 2) {
res = (c * c) % mod;
res *= a;
res %= mod;
} else
res = ((c * c) % mod);
return res;
}
// ifstream cin("b_read_on.txt"); ofstream cout("output3.txt");
// Chronology: Binary Search,Greedy,dp,dfs and similar
// Use (<<) for multiplication
// Use (>>) for division
// In dp, first try top-down,then bottom-up
// ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cout<<fixed;cerr.tie(NULL);
// find_by_order -> value at index
// order_of_key -> index of value
// while using (1<<i) use ((ll)1<<(ll)i)
// if global declared initialise per testcase
int n;
ll v[1001], w[1001], s[1001];
ll dp[1001][10001];
ll func(int i, ll s1) {
if (i == n)
return 0;
if (dp[i][s1] != -1)
return dp[i][s1];
ll ans = func(i + 1, s1);
if (w[i] <= s1)
ans = max(ans, func(i + 1, min(s[i], s1 - w[i])) + v[i]);
dp[i][s1] = ans;
return ans;
}
void solve(int countu) {
cin >> n;
vector<pair<pll, pll>> v1;
rep(i, n) {
ll w, s, v;
cin >> w >> s >> v;
v1.pb({{w + s, s}, {w, v}});
}
sort(v1.begin(), v1.end());
reverse(v1.begin(), v1.end());
rep(i, v1.size()) {
s[i] = v1[i].fi.se;
v[i] = v1[i].se.se;
w[i] = v1[i].se.fi;
}
memset(dp, -1, sizeof(dp));
cout1(func(0, inf));
}
int main() {
// ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cout<<fixed;cerr.tie(NULL);cout.precision(10);
int t = 1;
// scanf("%d",&t);
int countu = 1;
while (t--) {
solve(countu);
countu++;
}
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007
#include <string.h>
#define inf 9000000000000000000
#define maxn 200006
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;
#define endl '\n'
#define mapint_iterator map<int, int>::iterator
#define mapll_iterator map<ll, ll>::iterator
#define setint_iterator set<int>::iterator
#define setll_iterator set<ll>::iterator
#define setpint_iterator set<pint>::iterator
#define setpll_iterator set<pll>::iterator
#define trace(x) cout << #x << ": " << x << " " << endl
#define trace2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z) \
cout << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << endl
#define trace4(a, b, c, d) \
cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << endl
#define cout1(a) cout << a << endl
#define cout2(a, b) cout << a << ' ' << b << endl
#define cout3(a, b, c) cout << a << " " << b << " " << c << endl
#define cout4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
#define vcout(v, i) cout << v[i].fi << " " << v[i].se << endl
typedef priority_queue<ll, vector<ll>, greater<ll>> pqset;
typedef priority_queue<pint, vector<pint>, greater<pint>> pqset_ll;
#define pb push_back
#define fi first
#define se second
#include <ext/pb_ds/assoc_container.hpp>
ll dxk[] = {0, 0, 1, -1, 1, 1, -1, -1};
ll dyk[] = {1, -1, 0, 0, 1, -1, 1, -1};
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
os;
typedef tree<pll, null_type, less<pll>, rb_tree_tag,
tree_order_statistics_node_update>
os_pair;
#define acc (ios::sync_with_stdio(false), cin.tie(0))
#define rep(i, n) for (ll i = 0; i < n; i++)
#define per(i, n) for (ll i = n - 1; i >= 0; i--)
#define rep1(i, n) for (ll i = 1; i <= n; i++)
#define per1(i, n) for (ll i = n; i > 0; i--)
#define repeat(i, start, n) for (ll i = start; i < n; i++)
#define print(a, n) \
for (ll i = 0; i < n; i++) { \
cout << a[i] << " "; \
}
ll ll_max(ll a, ll b, ll c) { return max(a, max(b, c)); }
int int_max(int a, int b, int c) { return max(a, max(b, c)); }
ll ll_min(ll a, ll b, ll c) { return min(a, min(b, c)); }
int int_min(int a, int b, int c) { return min(a, min(b, c)); }
ll max(int a, ll b) { return max((ll)a, b); }
ll min(int a, ll b) { return min((ll)a, b); }
ll min(ll a, int b) { return min(a, (ll)b); }
ll max(ll a, int b) { return max(a, (ll)b); }
ll dx[] = {0, 0, 1, -1};
ll dy[] = {1, -1, 0, 0};
ll power(ll a, ll b) {
if (a == 1)
return 1;
if (b == 0)
return 1;
ll c = power(a, b / 2);
ll res = 1;
if (b % 2) {
res = (c * c) % mod;
res *= a;
res %= mod;
} else
res = ((c * c) % mod);
return res;
}
// ifstream cin("b_read_on.txt"); ofstream cout("output3.txt");
// Chronology: Binary Search,Greedy,dp,dfs and similar
// Use (<<) for multiplication
// Use (>>) for division
// In dp, first try top-down,then bottom-up
// ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cout<<fixed;cerr.tie(NULL);
// find_by_order -> value at index
// order_of_key -> index of value
// while using (1<<i) use ((ll)1<<(ll)i)
// if global declared initialise per testcase
int n;
ll v[1001], w[1001], s[1001];
ll dp[1001][20001];
ll func(int i, ll s1) {
if (i == n)
return 0;
if (dp[i][s1] != -1)
return dp[i][s1];
ll ans = func(i + 1, s1);
if (w[i] <= s1)
ans = max(ans, func(i + 1, min(s[i], s1 - w[i])) + v[i]);
dp[i][s1] = ans;
return ans;
}
void solve(int countu) {
cin >> n;
vector<pair<pll, pll>> v1;
rep(i, n) {
ll w, s, v;
cin >> w >> s >> v;
v1.pb({{w + s, s}, {w, v}});
}
sort(v1.begin(), v1.end());
reverse(v1.begin(), v1.end());
rep(i, v1.size()) {
s[i] = v1[i].fi.se;
v[i] = v1[i].se.se;
w[i] = v1[i].se.fi;
}
memset(dp, -1, sizeof(dp));
cout1(func(0, 20000));
}
int main() {
// ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cout<<fixed;cerr.tie(NULL);cout.precision(10);
int t = 1;
// scanf("%d",&t);
int countu = 1;
while (t--) {
solve(countu);
countu++;
}
}
| [
"literal.number.change",
"variable_declaration.array_dimensions.change",
"identifier.replace.remove",
"literal.replace.add",
"io.output.change"
] | 986,916 | 986,917 | u920271139 | cpp |
p03183 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define PB push_back
struct edge {
int to;
};
using graph = vector<vector<edge>>;
const int MAXN = 1000;
const int MAXS = 10000;
const ll INF = 1e15;
ll dp[MAXN + 5][2 * MAXS + 5];
ll best[MAXN + 5];
auto maxx(auto &a, auto b) { a = max(a, b); }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vi w(n), s(n), v(n);
rep(i, 0, n) { cin >> w[i] >> s[i] >> v[i]; }
vi ind(n);
iota(all(ind), 0);
sort(all(ind), [&](int i, int j) { return s[i] + w[i] < s[j] + w[j]; });
auto w2 = w, s2 = s, v2 = v;
rep(i, 0, n) {
int i2 = ind[i];
w[i] = w2[i2], s[i] = s2[i2], v[i] = v2[i2];
}
rep(i, 0, MAXN + 1) rep(j, 0, 2 * MAXS + 1) dp[i][j] = -1;
dp[0][0] = 0;
rep(i, 0, n) {
for (int weight = MAXS; weight >= 0; weight--) {
maxx(dp[i + 1][weight], dp[i][weight]);
if (weight <= s[i] and dp[i][weight] != -1) {
maxx(dp[i + 1][weight + w[i]], dp[i][weight] + v[i]);
// cout << "Can get: " << dp[i + 1][weight + w[i]] << endl;
}
}
// cout << dp[i + 1][1] << " " << dp[i + 1][2] << " " << dp[i + 1][3] <<
// endl;
}
auto res = 0LL;
rep(i, 0, n) { maxx(res, *max_element(all(dp[i]))); }
cout << res << '\n';
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define PB push_back
struct edge {
int to;
};
using graph = vector<vector<edge>>;
const int MAXN = 1000;
const int MAXS = 10000;
const ll INF = 1e15;
ll dp[MAXN + 5][2 * MAXS + 5];
ll best[MAXN + 5];
auto maxx(auto &a, auto b) { a = max(a, b); }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vi w(n), s(n), v(n);
rep(i, 0, n) { cin >> w[i] >> s[i] >> v[i]; }
vi ind(n);
iota(all(ind), 0);
sort(all(ind), [&](int i, int j) { return s[i] + w[i] < s[j] + w[j]; });
auto w2 = w, s2 = s, v2 = v;
rep(i, 0, n) {
int i2 = ind[i];
w[i] = w2[i2], s[i] = s2[i2], v[i] = v2[i2];
}
rep(i, 0, MAXN + 1) rep(j, 0, 2 * MAXS + 1) dp[i][j] = -1;
dp[0][0] = 0;
rep(i, 0, n) {
for (int weight = MAXS; weight >= 0; weight--) {
maxx(dp[i + 1][weight], dp[i][weight]);
if (weight <= s[i] and dp[i][weight] != -1) {
maxx(dp[i + 1][weight + w[i]], dp[i][weight] + v[i]);
// cout << "Can get: " << dp[i + 1][weight + w[i]] << endl;
}
}
// cout << dp[i + 1][1] << " " << dp[i + 1][2] << " " << dp[i + 1][3] <<
// endl;
}
auto res = 0LL;
rep(i, 0, n + 1) { maxx(res, *max_element(all(dp[i]))); }
cout << res << '\n';
}
| [
"expression.operation.binary.add"
] | 986,931 | 986,932 | u092269433 | cpp |
p03183 | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = a; i >= (int)b; i--)
#define R0F(i, a) ROF(i, a, 0)
#define GO(i, a) for (auto i : a)
#define rsz resize
#define eb emplace_back
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define f first
#define s second
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vpii> vvpii;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef vector<pi64> vpi64;
const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};
const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};
const int ms[] = {+31, +29, +31, 30, +31, +30, +31, +31, +30, +31, +30, +31};
const int N = 1e3 + 5;
const int M = 2e4 + 5;
int n;
i64 dp[N][M];
struct E {
int peso, aguenta, profit;
bool operator<(E Other) const {
return peso + aguenta < Other.peso + Other.aguenta;
}
} a[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
F0R(i, n) cin >> a[i].peso >> a[i].aguenta >> a[i].profit;
sort(a, a + n);
FOR(i, 1, n + 1) {
FOR(j, 0, M) {
dp[i][j] = max(dp[i][j], dp[i - 1][j]);
if (j - a[i - 1].peso >= 0) {
int mn = min(j - a[i - 1].peso, a[i - 1].aguenta);
dp[i][mn] = max(dp[i][mn], dp[i - 1][j] + a[i - 1].profit);
}
}
}
i64 mx = 0;
FOR(i, 1, n + 1) {
FOR(j, 0, M) { mx = max(mx, dp[i][j]); }
}
cout << mx << '\n';
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = a; i >= (int)b; i--)
#define R0F(i, a) ROF(i, a, 0)
#define GO(i, a) for (auto i : a)
#define rsz resize
#define eb emplace_back
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define f first
#define s second
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vpii> vvpii;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef vector<pi64> vpi64;
const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};
const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};
const int ms[] = {+31, +29, +31, 30, +31, +30, +31, +31, +30, +31, +30, +31};
const int N = 1e3 + 5;
const int M = 2e4 + 5;
int n;
i64 dp[N][M];
struct E {
int peso, aguenta, profit;
bool operator<(E Other) const {
return peso + aguenta > Other.peso + Other.aguenta;
}
} a[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
F0R(i, n) cin >> a[i].peso >> a[i].aguenta >> a[i].profit;
sort(a, a + n);
FOR(i, 1, n + 1) {
FOR(j, 0, M) {
dp[i][j] = max(dp[i][j], dp[i - 1][j]);
if (j - a[i - 1].peso >= 0) {
int mn = min(j - a[i - 1].peso, a[i - 1].aguenta);
dp[i][mn] = max(dp[i][mn], dp[i - 1][j] + a[i - 1].profit);
}
}
}
i64 mx = 0;
FOR(i, 1, n + 1) {
FOR(j, 0, M) { mx = max(mx, dp[i][j]); }
}
cout << mx << '\n';
return 0;
}
| [
"misc.opposites",
"expression.operator.compare.change",
"function.return_value.change",
"expression.operation.binary.change"
] | 986,982 | 986,983 | u767093102 | cpp |
p03183 | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = a; i >= (int)b; i--)
#define R0F(i, a) ROF(i, a, 0)
#define GO(i, a) for (auto i : a)
#define rsz resize
#define eb emplace_back
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define f first
#define s second
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vpii> vvpii;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef vector<pi64> vpi64;
const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};
const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};
const int ms[] = {+31, +29, +31, 30, +31, +30, +31, +31, +30, +31, +30, +31};
const int N = 1e3 + 5;
const int M = 1e4 + 5;
int n;
i64 dp[N][M];
struct E {
int peso, aguenta, profit;
bool operator<(E Other) const {
return peso + aguenta > Other.peso + Other.aguenta;
}
} a[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
F0R(i, n) cin >> a[i].peso >> a[i].aguenta >> a[i].profit;
sort(a, a + n);
FOR(i, 1, n + 1) {
FOR(j, 1, M) {
dp[i][j] = max(dp[i][j], dp[i - 1][j]);
if (j - a[i - 1].peso >= 0) {
int mn = min(j - a[i - 1].peso, a[i - 1].aguenta);
dp[i][mn] = max(dp[i][mn], dp[i - 1][j] + a[i - 1].profit);
}
}
}
i64 mx = 0;
FOR(i, 1, n + 1) {
FOR(j, 0, M) { mx = max(mx, dp[i][j]); }
}
cout << mx << '\n';
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = a; i >= (int)b; i--)
#define R0F(i, a) ROF(i, a, 0)
#define GO(i, a) for (auto i : a)
#define rsz resize
#define eb emplace_back
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define f first
#define s second
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vpii> vvpii;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef vector<pi64> vpi64;
const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};
const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};
const int ms[] = {+31, +29, +31, 30, +31, +30, +31, +31, +30, +31, +30, +31};
const int N = 1e3 + 5;
const int M = 2e4 + 5;
int n;
i64 dp[N][M];
struct E {
int peso, aguenta, profit;
bool operator<(E Other) const {
return peso + aguenta > Other.peso + Other.aguenta;
}
} a[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
F0R(i, n) cin >> a[i].peso >> a[i].aguenta >> a[i].profit;
sort(a, a + n);
FOR(i, 1, n + 1) {
FOR(j, 0, M) {
dp[i][j] = max(dp[i][j], dp[i - 1][j]);
if (j - a[i - 1].peso >= 0) {
int mn = min(j - a[i - 1].peso, a[i - 1].aguenta);
dp[i][mn] = max(dp[i][mn], dp[i - 1][j] + a[i - 1].profit);
}
}
}
i64 mx = 0;
FOR(i, 1, n + 1) {
FOR(j, 0, M) { mx = max(mx, dp[i][j]); }
}
cout << mx << '\n';
return 0;
}
| [
"literal.number.change",
"expression.operation.binary.change",
"call.arguments.change"
] | 986,985 | 986,983 | u767093102 | cpp |
p03183 | #include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n;
long long dp[N], ans;
struct node {
int w, s;
long long v;
} a[N];
bool cmp(node x, node y) { return x.w + x.s < y.w + y.s; }
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d%d%lld", &a[i].w, &a[i].s, &a[i].v);
}
sort(a + 1, a + n + 1, cmp);
for (int i = 1; i <= n; i++) {
for (int j = a[i].s; j >= 0; j--) {
dp[j + a[i].w] = max(dp[j + a[i].w], dp[j] + a[i].v);
ans = max(ans, dp[j + a[i].s]);
}
}
printf("%lld\n", ans);
} | #include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n;
long long dp[N], ans;
struct node {
int w, s;
long long v;
} a[N];
bool cmp(node x, node y) { return x.w + x.s < y.w + y.s; }
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d%d%lld", &a[i].w, &a[i].s, &a[i].v);
}
sort(a + 1, a + n + 1, cmp);
for (int i = 1; i <= n; i++) {
for (int j = a[i].s; j >= 0; j--) {
dp[j + a[i].w] = max(dp[j + a[i].w], dp[j] + a[i].v);
ans = max(ans, dp[j + a[i].w]);
}
}
printf("%lld\n", ans);
} | [
"assignment.value.change",
"variable_access.subscript.index.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 986,994 | 986,995 | u541361127 | cpp |
p03183 | #include <algorithm>
#include <iostream>
using namespace std;
const int MAXN = 1000 + 10;
const int MAXNA = 20000 + 20;
int n, ans;
int dp[MAXNA];
struct p {
int w;
int s;
int v;
} A[MAXN];
bool cmp(p a, p b) { return (a.w + a.s) < (b.w + b.s); }
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> A[i].w >> A[i].s >> A[i].v;
}
// cout<<"\n";
sort(A, A + n, cmp);
for (int i = 1; i <= n; i++) {
for (int j = A[i].s; j >= 0; j--) {
dp[j + A[i].w] = max(dp[j + A[i].w], dp[j] + A[i].v);
}
}
for (int i = 0; i <= MAXNA - 1; i++) {
ans = max(ans, dp[i]);
}
cout << ans;
return 0;
} | #include <algorithm>
#include <iostream>
using namespace std;
const int MAXN = 1000 + 10;
const int MAXNA = 20000 + 20;
long long n, ans;
long long dp[MAXNA];
struct p {
int w;
int s;
int v;
} A[MAXN];
bool cmp(p a, p b) { return (a.w + a.s) < (b.w + b.s); }
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> A[i].w >> A[i].s >> A[i].v;
}
// cout<<"\n";
sort(A, A + n + 1, cmp);
for (int i = 1; i <= n; i++) {
for (int j = A[i].s; j >= 0; j--) {
dp[j + A[i].w] = max(dp[j + A[i].w], dp[j] + A[i].v);
}
}
for (int i = 0; i <= MAXNA - 1; i++) {
ans = max(ans, dp[i]);
}
cout << ans;
return 0;
} | [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 987,025 | 987,026 | u803932112 | cpp |
p03181 | #include <bits/stdc++.h>
#define ll long long
#define PB push_back
#define MP make_pair
#define ff first
#define ss second
using namespace std;
ll dp[100001] = {0}, ans[100001] = {0}, M, dpup[100001] = {0};
ll dfs(ll pt, vector<pair<ll, pair<ll, ll>>> adj[], ll old) {
ll v = 1;
vector<ll> vs;
ll zes = 0;
ll xas = adj[pt].size();
for (ll i = 0; i < xas; i++) {
ll ne = adj[pt][i].ff;
if (ne == old)
continue;
ll sa = dfs(ne, adj, pt);
v = (v * sa) % M;
vs.PB(sa);
adj[pt][i].ss.ff = v;
}
ll ze = 1;
ll xa = adj[pt].size();
ll za = vs.size() - 1;
for (ll z = xa - 1; z >= 0; z--) {
ll ne = adj[pt][z].ff;
if (ne == old)
continue;
ze = (ze * vs[za]) % M;
za--;
adj[pt][z].ss.ss = ze;
}
dp[pt] = v;
return (v + 1) % M;
}
ll dfs2(ll pt, vector<pair<ll, pair<ll, ll>>> adj[], ll old) {
if (old == -1) {
ans[pt] = dp[pt];
} else {
dpup[pt] = (dpup[old] * dpup[pt] + 1) % M;
ll an = (dp[pt] * (dpup[pt])) % M;
ans[pt] = an;
}
ll ze = -1;
ll x = adj[pt].size();
for (ll i = 0; i < x; i++) {
ll ne = adj[pt][i].ff;
if (ne == old)
continue;
if (ze != -1) {
ll zx = adj[pt][ze].ff;
dpup[ne] = (adj[pt][ze].ss.ff) % M;
dpup[zx] = (dpup[zx] * adj[pt][ne].ss.ss) % M;
}
ze = i;
}
for (ll i = 0; i < x; i++) {
ll ne = adj[pt][i].ff;
if (ne == old)
continue;
dfs2(ne, adj, pt);
}
}
void run() {
ll n, m;
cin >> n >> M;
vector<pair<ll, pair<ll, ll>>> adj[n + 1];
for (ll i = 0; i < n - 1; i++) {
ll x, y;
cin >> x >> y;
ll s = 1;
adj[x].PB(MP(y, MP(s, s)));
adj[y].PB(MP(x, MP(s, s)));
dpup[i + 1] = 1;
}
dpup[n] = 1;
dfs(1, adj, -1);
dfs2(1, adj, -1);
for (ll j = 1; j <= n; j++) {
cout << ans[j] << endl;
;
}
}
int main() {
ll t = 1;
// cin>>t;
for (ll i = 0; i < t; i++)
run();
// your code goes here
return 0;
} | #include <bits/stdc++.h>
#define ll long long
#define PB push_back
#define MP make_pair
#define ff first
#define ss second
using namespace std;
ll dp[100001] = {0}, ans[100001] = {0}, M, dpup[100001] = {0};
ll dfs(ll pt, vector<pair<ll, pair<ll, ll>>> adj[], ll old) {
ll v = 1;
vector<ll> vs;
ll zes = 0;
ll xas = adj[pt].size();
for (ll i = 0; i < xas; i++) {
ll ne = adj[pt][i].ff;
if (ne == old)
continue;
ll sa = dfs(ne, adj, pt);
v = (v * sa) % M;
vs.PB(sa);
// cout<<sa<<endl;
adj[pt][i].ss.ff = v;
}
ll ze = 1;
ll xa = adj[pt].size();
ll za = vs.size() - 1;
for (ll z = xa - 1; z >= 0; z--) {
ll ne = adj[pt][z].ff;
if (ne == old)
continue;
ze = (ze * vs[za]) % M;
// cout<<ze<<pt<<z<<endl;
za--;
adj[pt][z].ss.ss = ze;
}
dp[pt] = v;
return (v + 1) % M;
}
ll dfs2(ll pt, vector<pair<ll, pair<ll, ll>>> adj[], ll old) {
if (old == -1) {
ans[pt] = dp[pt];
} else {
// cout<<dpup[old]<<" "<<dpup[pt]<<endl;
dpup[pt] = (dpup[old] * dpup[pt] + 1) % M;
ll an = (dp[pt] * (dpup[pt])) % M;
ans[pt] = an;
}
ll ze = -1;
ll x = adj[pt].size();
for (ll i = 0; i < x; i++) {
ll ne = adj[pt][i].ff;
if (ne == old)
continue;
if (ze != -1) {
ll zx = adj[pt][ze].ff;
dpup[ne] = (adj[pt][ze].ss.ff) % M;
dpup[zx] = (dpup[zx] * adj[pt][i].ss.ss) % M;
// cout<<adj[pt][i].ss.ss<<" "<<i<<" "<<pt<<endl;
}
ze = i;
}
for (ll i = 0; i < x; i++) {
ll ne = adj[pt][i].ff;
if (ne == old)
continue;
dfs2(ne, adj, pt);
}
}
void run() {
ll n, m;
cin >> n >> M;
vector<pair<ll, pair<ll, ll>>> adj[n + 1];
for (ll i = 0; i < n - 1; i++) {
ll x, y;
cin >> x >> y;
ll s = 1;
adj[x].PB(MP(y, MP(s, s)));
adj[y].PB(MP(x, MP(s, s)));
dpup[i + 1] = 1;
}
dpup[n] = 1;
dfs(1, adj, -1);
dfs2(1, adj, -1);
for (ll j = 1; j <= n; j++) {
cout << ans[j] << endl;
;
}
}
int main() {
ll t = 1;
// cin>>t;
for (ll i = 0; i < t; i++)
run();
// your code goes here
return 0;
} | [
"assignment.value.change",
"identifier.change",
"variable_access.subscript.index.change",
"expression.operation.binary.change"
] | 987,032 | 987,033 | u874786170 | cpp |
p03181 | #include <bits/stdc++.h>
using namespace std;
int n, m, tot = 0, head[100001], nxt[200002], to[200002];
long long g[100001], f[100001];
vector<long long> pre[100001], rev[100001];
void addedge(int u, int v) {
++tot;
nxt[tot] = head[u];
to[tot] = v;
head[u] = tot;
return;
}
long long dfs(int index, int p) {
int flag = 0, u, v, i;
g[index] = 1;
vector<long long> tmp;
for (u = head[index]; u; u = nxt[u]) {
v = to[u];
if (v == p)
continue;
flag = 1;
g[index] = g[index] * (dfs(v, index) + 1) % m;
tmp.push_back(g[v] + 1);
// printf("&&&%lld %d\n",g[v],index);
}
if (flag) {
pre[index].resize(tmp.size() + 1);
pre[index][1] = 1;
rev[index].resize(tmp.size() + 2);
rev[index][tmp.size()] = 1;
for (i = 2; i <= tmp.size(); i++) {
pre[index][i] = pre[index][i - 1] * tmp[i - 1] % m;
// printf("ppp %d %d %lld\n",index,i,pre[index][i]);
}
for (i = tmp.size() - 1; i >= 1; i--) {
rev[index][i] = rev[index][i + 1] * tmp[i] % m;
// printf("rrr %d %d %lld\n",index,i,rev[index][i]);
}
}
return g[index];
}
void ddfs(int index, int k, int p) {
int u, v, l = 0;
f[index] = k * g[index] % m;
// printf("%d %d %d\n",index,k,p);
for (u = head[index]; u; u = nxt[u]) {
v = to[u];
if (v != p) {
l++;
// printf("***%lld %lld\n",pre[index][l],rev[index][l]);
ddfs(v, (pre[index][l] * rev[index][l] % m * k % m + 1) % m, index);
}
}
}
int main() {
int i, u, v, j;
scanf("%d%d", &n, &m);
for (i = 1; i < n; i++) {
scanf("%d%d", &u, &v);
addedge(u, v);
addedge(v, u);
}
dfs(1, 0);
/*for(i=1;i<=n;i++)
{
for(j=1;j<=pre[i].size()-1;j++)
printf("%lld ",pre[i][j]);
printf("\n");
}*/
ddfs(1, 1, 0);
for (i = 1; i <= n; i++)
printf("%lld\n", f[i] % m);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int n, m, tot = 0, head[100001], nxt[200002], to[200002];
long long g[100001], f[100001];
vector<long long> pre[100001], rev[100001];
void addedge(int u, int v) {
++tot;
nxt[tot] = head[u];
to[tot] = v;
head[u] = tot;
return;
}
long long dfs(int index, int p) {
int flag = 0, u, v, i;
g[index] = 1;
vector<long long> tmp;
for (u = head[index]; u; u = nxt[u]) {
v = to[u];
if (v == p)
continue;
flag = 1;
g[index] = g[index] * (dfs(v, index) + 1) % m;
tmp.push_back(g[v] + 1);
// printf("&&&%lld %d\n",g[v],index);
}
if (flag) {
pre[index].resize(tmp.size() + 1);
pre[index][1] = 1;
rev[index].resize(tmp.size() + 2);
rev[index][tmp.size()] = 1;
for (i = 2; i <= tmp.size(); i++) {
pre[index][i] = pre[index][i - 1] * tmp[i - 2] % m;
// printf("ppp %d %d %lld\n",index,i,pre[index][i]);
}
for (i = tmp.size() - 1; i >= 1; i--) {
rev[index][i] = rev[index][i + 1] * tmp[i] % m;
// printf("rrr %d %d %lld\n",index,i,rev[index][i]);
}
}
return g[index];
}
void ddfs(int index, int k, int p) {
int u, v, l = 0;
f[index] = k * g[index] % m;
// printf("%d %d %d\n",index,k,p);
for (u = head[index]; u; u = nxt[u]) {
v = to[u];
if (v != p) {
l++;
// printf("***%lld %lld\n",pre[index][l],rev[index][l]);
ddfs(v, (pre[index][l] * rev[index][l] % m * k % m + 1) % m, index);
}
}
}
int main() {
int i, u, v, j;
scanf("%d%d", &n, &m);
for (i = 1; i < n; i++) {
scanf("%d%d", &u, &v);
addedge(u, v);
addedge(v, u);
}
dfs(1, 0);
/*for(i=1;i<=n;i++)
{
for(j=1;j<=pre[i].size()-1;j++)
printf("%lld ",pre[i][j]);
printf("\n");
}*/
ddfs(1, 1, 0);
for (i = 1; i <= n; i++)
printf("%lld\n", f[i] % m);
return 0;
} | [
"literal.number.change",
"assignment.value.change",
"variable_access.subscript.index.change",
"expression.operation.binary.change"
] | 987,036 | 987,037 | u314499126 | cpp |
p03181 | #include <bits/stdc++.h>
using namespace std;
int n, m, tot = 0, head[100001], nxt[200002], to[200002];
long long g[100001], f[100001];
vector<long long> pre[100001], rev[100001];
void addedge(int u, int v) {
++tot;
nxt[tot] = head[u];
to[tot] = v;
head[u] = tot;
return;
}
long long dfs(int index, int p) {
int flag = 0, u, v, i;
g[index] = 1;
vector<long long> tmp;
for (u = head[index]; u; u = nxt[u]) {
v = to[u];
if (v == p)
continue;
flag = 1;
g[index] = g[index] * (dfs(v, index) + 1) % m;
tmp.push_back(g[v] + 1);
// printf("&&&%lld %d\n",g[v],index);
}
if (flag) {
pre[index].resize(tmp.size() + 1);
pre[index][1] = 1;
rev[index].resize(tmp.size() + 2);
rev[index][tmp.size()] = 1;
for (i = 2; i <= tmp.size(); i++) {
pre[index][i] = pre[index][i - 1] * tmp[i - 1] % m;
// printf("ppp %d %d %lld\n",index,i,pre[index][i]);
}
for (i = tmp.size() - 1; i >= 1; i--) {
rev[index][i] = rev[index][i + 1] * tmp[i - 1] % m;
// printf("rrr %d %d %lld\n",index,i,rev[index][i]);
}
}
return g[index];
}
void ddfs(int index, int k, int p) {
int u, v, l = 0;
f[index] = k * g[index] % m;
// printf("%d %d %d\n",index,k,p);
for (u = head[index]; u; u = nxt[u]) {
v = to[u];
if (v != p) {
l++;
// printf("***%lld %lld\n",pre[index][l],rev[index][l]);
ddfs(v, (pre[index][l] * rev[index][l] % m * k % m + 1) % m, index);
}
}
}
int main() {
int i, u, v, j;
scanf("%d%d", &n, &m);
for (i = 1; i < n; i++) {
scanf("%d%d", &u, &v);
addedge(u, v);
addedge(v, u);
}
dfs(1, 0);
/*for(i=1;i<=n;i++)
{
for(j=1;j<=pre[i].size()-1;j++)
printf("%lld ",pre[i][j]);
printf("\n");
}*/
ddfs(1, 1, 0);
for (i = 1; i <= n; i++)
printf("%lld\n", f[i] % m);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int n, m, tot = 0, head[100001], nxt[200002], to[200002];
long long g[100001], f[100001];
vector<long long> pre[100001], rev[100001];
void addedge(int u, int v) {
++tot;
nxt[tot] = head[u];
to[tot] = v;
head[u] = tot;
return;
}
long long dfs(int index, int p) {
int flag = 0, u, v, i;
g[index] = 1;
vector<long long> tmp;
for (u = head[index]; u; u = nxt[u]) {
v = to[u];
if (v == p)
continue;
flag = 1;
g[index] = g[index] * (dfs(v, index) + 1) % m;
tmp.push_back(g[v] + 1);
// printf("&&&%lld %d\n",g[v],index);
}
if (flag) {
pre[index].resize(tmp.size() + 1);
pre[index][1] = 1;
rev[index].resize(tmp.size() + 2);
rev[index][tmp.size()] = 1;
for (i = 2; i <= tmp.size(); i++) {
pre[index][i] = pre[index][i - 1] * tmp[i - 2] % m;
// printf("ppp %d %d %lld\n",index,i,pre[index][i]);
}
for (i = tmp.size() - 1; i >= 1; i--) {
rev[index][i] = rev[index][i + 1] * tmp[i] % m;
// printf("rrr %d %d %lld\n",index,i,rev[index][i]);
}
}
return g[index];
}
void ddfs(int index, int k, int p) {
int u, v, l = 0;
f[index] = k * g[index] % m;
// printf("%d %d %d\n",index,k,p);
for (u = head[index]; u; u = nxt[u]) {
v = to[u];
if (v != p) {
l++;
// printf("***%lld %lld\n",pre[index][l],rev[index][l]);
ddfs(v, (pre[index][l] * rev[index][l] % m * k % m + 1) % m, index);
}
}
}
int main() {
int i, u, v, j;
scanf("%d%d", &n, &m);
for (i = 1; i < n; i++) {
scanf("%d%d", &u, &v);
addedge(u, v);
addedge(v, u);
}
dfs(1, 0);
/*for(i=1;i<=n;i++)
{
for(j=1;j<=pre[i].size()-1;j++)
printf("%lld ",pre[i][j]);
printf("\n");
}*/
ddfs(1, 1, 0);
for (i = 1; i <= n; i++)
printf("%lld\n", f[i] % m);
return 0;
} | [
"literal.number.change",
"assignment.value.change",
"variable_access.subscript.index.change",
"expression.operation.binary.change",
"expression.operation.binary.remove"
] | 987,038 | 987,037 | u314499126 | cpp |
p03181 | #include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long long LL;
typedef pair<int, int> P;
const LL mod = 1000000007;
const LL LINF = 1LL << 62;
const LL INF = 1 << 17;
int m;
vector<int> v[100001];
vector<LL> dp1(100001, -1);
vector<LL> dp2(100001, -1);
int dfs1(int u, int prev) {
LL ret = 1;
for (int i = 0; i < v[u].size(); i++) {
if (v[u][i] == prev)
continue;
ret = (ret * dfs1(v[u][i], u)) % m;
}
return dp1[u] = ret + 1;
}
void dfs2(int u, int prev, LL ts) {
if (dp2[u] == -1) {
dp2[u] = 1;
for (int i = 0; i < v[u].size(); i++) {
if (v[u][i] == prev) {
dp2[u] = (dp2[u] * (ts + 1)) % m;
} else {
dp2[u] = (dp2[u] * dp1[v[u][i]]) % m;
}
}
dp2[u]++;
}
vector<LL> l(v[u].size() + 1, 1), r(v[u].size() + 1, 1);
for (int i = 0; i < v[u].size(); i++) {
l[i + 1] = (l[i] * (v[u][i] == prev ? (ts + 1) : dp1[v[u][i]])) % m;
}
for (int i = v[u].size(); i >= 1; i--) {
r[i - 1] = (r[i] * (v[u][i] == prev ? (ts + 1) : dp1[v[u][i - 1]])) % m;
}
for (int i = 0; i < v[u].size(); i++) {
if (v[u][i] == prev)
continue;
dfs2(v[u][i], u, (l[i] * r[i + 1]) % m);
}
}
int main() {
int N;
cin >> N >> m;
for (int i = 0; i < N - 1; i++) {
int x, y;
cin >> x >> y;
x--, y--;
v[x].pb(y);
v[y].pb(x);
}
dfs1(0, 0);
dp2[0] = dp1[0];
dfs2(0, 0, 0);
for (int i = 0; i < N; i++) {
cout << (dp2[i] + m - 1) % m << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long long LL;
typedef pair<int, int> P;
const LL mod = 1000000007;
const LL LINF = 1LL << 62;
const LL INF = 1 << 17;
int m;
vector<int> v[100001];
vector<LL> dp1(100001, -1);
vector<LL> dp2(100001, -1);
int dfs1(int u, int prev) {
LL ret = 1;
for (int i = 0; i < v[u].size(); i++) {
if (v[u][i] == prev)
continue;
ret = (ret * dfs1(v[u][i], u)) % m;
}
return dp1[u] = ret + 1;
}
void dfs2(int u, int prev, LL ts) {
if (dp2[u] == -1) {
dp2[u] = 1;
for (int i = 0; i < v[u].size(); i++) {
if (v[u][i] == prev) {
dp2[u] = (dp2[u] * (ts + 1)) % m;
} else {
dp2[u] = (dp2[u] * dp1[v[u][i]]) % m;
}
}
dp2[u]++;
}
vector<LL> l(v[u].size() + 1, 1), r(v[u].size() + 1, 1);
for (int i = 0; i < v[u].size(); i++) {
l[i + 1] = (l[i] * (v[u][i] == prev ? (ts + 1) : dp1[v[u][i]])) % m;
}
for (int i = v[u].size(); i >= 1; i--) {
r[i - 1] = (r[i] * (v[u][i - 1] == prev ? (ts + 1) : dp1[v[u][i - 1]])) % m;
}
for (int i = 0; i < v[u].size(); i++) {
if (v[u][i] == prev)
continue;
dfs2(v[u][i], u, (l[i] * r[i + 1]) % m);
}
}
int main() {
int N;
cin >> N >> m;
for (int i = 0; i < N - 1; i++) {
int x, y;
cin >> x >> y;
x--, y--;
v[x].pb(y);
v[y].pb(x);
}
dfs1(0, 0);
dp2[0] = dp1[0];
dfs2(0, 0, 0);
for (int i = 0; i < N; i++) {
cout << (dp2[i] + m - 1) % m << endl;
}
return 0;
}
| [
"control_flow.loop.for.condition.change",
"misc.off_by_one",
"assignment.change"
] | 987,041 | 987,042 | u640323045 | cpp |
p03181 | #include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, a, b) for (ll i = ll(a); i < ll(b); i++)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
typedef long long ll;
using namespace std;
ll mod;
vector<vector<ll>> to;
vector<ll> dp[100001];
ll ans[100001];
ll dfs(ll v, ll p = -1) {
ll m = to[v].size();
dp[v].resize(m);
ll res = 1;
rep(i, m) {
ll u = to[v][i];
if (u == p)
continue;
dp[v][i] = (dfs(u, v) + 1) % mod;
res = (ll)res * dp[v][i] % mod;
}
return res;
}
void efs(ll v, ll x, ll p = -1) {
ll m = to[v].size();
rep(i, m) {
ll u = to[v][i];
if (p == u)
dp[v][i] = x + 1;
}
vector<ll> l = dp[v], r = dp[v];
rep(i, m - 1) l[i + 1] = ((ll)l[i] * l[i + 1]) % mod;
for (ll i = m - 1; i >= 1; i--)
r[i - 1] = (ll)r[i] * r[i - 1] % mod;
ans[v] = l.back();
rep(i, m) {
ll u = to[v][i];
if (u == p)
continue;
x = 1;
if (i)
x = (ll)x * l[i - 1] % mod;
if (i + 1 < m)
x = (ll)x * r[i + 1] % mod;
efs(u, x, v);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll n;
cin >> n >> mod;
to.resize(n);
if (n == 1) {
cout << 1 << endl;
return 0;
}
rep(i, n - 1) {
ll a, b;
cin >> a >> b;
a--;
b--;
to[a].push_back(b);
to[b].push_back(a);
}
ll x = dfs(0);
efs(0, x);
rep(i, n) { cout << ans[i] << "\n"; }
cout << flush;
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, a, b) for (ll i = ll(a); i < ll(b); i++)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
typedef long long ll;
using namespace std;
ll mod;
vector<vector<ll>> to;
vector<ll> dp[100001];
ll ans[100001];
ll dfs(ll v, ll p = -1) {
ll m = to[v].size();
dp[v].resize(m);
ll res = 1;
rep(i, m) {
ll u = to[v][i];
if (u == p)
continue;
dp[v][i] = (dfs(u, v) + 1) % mod;
res = (ll)res * dp[v][i] % mod;
}
return res;
}
void efs(ll v, ll x, ll p = -1) {
ll m = to[v].size();
rep(i, m) {
ll u = to[v][i];
if (p == u)
dp[v][i] = (x + 1) % mod;
}
vector<ll> l = dp[v], r = dp[v];
rep(i, m - 1) l[i + 1] = ((ll)l[i] * l[i + 1]) % mod;
for (ll i = m - 1; i >= 1; i--)
r[i - 1] = (ll)r[i] * r[i - 1] % mod;
ans[v] = l.back();
rep(i, m) {
ll u = to[v][i];
if (u == p)
continue;
x = 1;
if (i)
x = (ll)x * l[i - 1] % mod;
if (i + 1 < m)
x = (ll)x * r[i + 1] % mod;
efs(u, x, v);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll n;
cin >> n >> mod;
to.resize(n);
if (n == 1) {
cout << 1 << endl;
return 0;
}
rep(i, n - 1) {
ll a, b;
cin >> a >> b;
a--;
b--;
to[a].push_back(b);
to[b].push_back(a);
}
ll x = dfs(0);
efs(0, x);
rep(i, n) { cout << ans[i] << "\n"; }
cout << flush;
return 0;
}
| [
"assignment.change"
] | 987,043 | 987,044 | u834415466 | cpp |
p03181 | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define MOD 1000000007
typedef long long ll;
using namespace std;
int N, M;
vector<int> g[100010];
ll dp[100010];
ll ans[100010];
vector<ll> child[100010];
ll dfs(int now, int par) {
ll res = 1;
for (int nex : g[now]) {
if (nex == par)
continue;
ll z = dfs(nex, now);
child[now].push_back(z);
res = res * (z + 1) % M;
}
res = (res + M) % M;
return dp[now] = res;
}
void solve(int now, int par, ll pans) {
if (par != -1) {
ll res = pans + 1;
for (int i = 0; i < child[now].size(); i++) {
res = (res * (child[now][i] + 1)) % M;
}
ans[now] = res;
}
int n = child[now].size();
vector<ll> left(n + 2), right(n + 2);
left[0] = 1;
right[n + 1] = 1;
for (int i = 1; i <= n; i++)
left[i] = (left[i - 1] * (child[now][i - 1] + 1) % M) % M;
for (int i = n; i >= 1; i--)
right[i] = (right[i + 1] * (child[now][i - 1] + 1) % M) % M;
int p = 0;
for (int i = 0; i < g[now].size(); i++) {
if (g[now][i] == par) {
p = 1;
continue;
}
solve(g[now][i], now,
((left[i - p] * right[i + 2 - p]) % M * (pans + 1) % M) % M);
}
}
int main() {
cin >> N >> M;
for (int i = 1; i < N; i++) {
int x, y;
cin >> x >> y;
x--;
y--;
g[x].push_back(y);
g[y].push_back(x);
}
ans[0] = dfs(0, 0);
solve(0, -1, 0);
for (int i = 0; i < N; i++)
cout << ans[i] << endl;
return 0;
}
| #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define MOD 1000000007
typedef long long ll;
using namespace std;
int N, M;
vector<int> g[100010];
ll dp[100010];
ll ans[100010];
vector<ll> child[100010];
ll dfs(int now, int par) {
ll res = 1;
for (int nex : g[now]) {
if (nex == par)
continue;
ll z = dfs(nex, now);
child[now].push_back(z);
res = res * (z + 1) % M;
}
res = (res + M) % M;
return dp[now] = res;
}
void solve(int now, int par, ll pans) {
if (par != -1) {
ll res = (pans + 1) % M;
for (int i = 0; i < child[now].size(); i++) {
res = (res * (child[now][i] + 1)) % M;
}
ans[now] = res;
}
int n = child[now].size();
vector<ll> left(n + 2), right(n + 2);
left[0] = 1;
right[n + 1] = 1;
for (int i = 1; i <= n; i++)
left[i] = (left[i - 1] * (child[now][i - 1] + 1) % M) % M;
for (int i = n; i >= 1; i--)
right[i] = (right[i + 1] * (child[now][i - 1] + 1) % M) % M;
int p = 0;
for (int i = 0; i < g[now].size(); i++) {
if (g[now][i] == par) {
p = 1;
continue;
}
solve(g[now][i], now,
((left[i - p] * right[i + 2 - p]) % M * (pans + 1) % M) % M);
}
}
int main() {
cin >> N >> M;
for (int i = 1; i < N; i++) {
int x, y;
cin >> x >> y;
x--;
y--;
g[x].push_back(y);
g[y].push_back(x);
}
ans[0] = dfs(0, 0);
solve(0, -1, 0);
for (int i = 0; i < N; i++)
cout << ans[i] << endl;
return 0;
}
| [
"assignment.change"
] | 987,045 | 987,046 | u646339490 | cpp |
p03181 | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define MOD 1000000007
typedef long long ll;
using namespace std;
int N, M;
vector<int> g[100010];
ll dp[100010];
ll ans[100010];
vector<ll> child[100010];
ll dfs(int now, int par) {
ll res = 1;
for (int nex : g[now]) {
if (nex == par)
continue;
ll z = dfs(nex, now);
child[now].push_back(z);
res = res * (z + 1) % M;
}
res = (res + M) % M;
return dp[now] = res;
}
void solve(int now, int par, ll pans) {
if (par != -1) {
ll res = pans + 1;
for (int i = 0; i < child[now].size(); i++) {
res = (res * (child[now][i] + 1)) % M;
}
ans[now] = res;
}
int n = child[now].size();
vector<ll> left(n + 2), right(n + 2);
left[0] = 1;
right[n + 1] = 1;
for (int i = 1; i <= n; i++)
left[i] = (left[i - 1] * (child[now][i - 1] + 1) % M) % M;
for (int i = n; i >= 1; i--)
right[i] = (right[i + 1] * (child[now][i - 1] + 1) % M) % M;
int p = 0;
for (int i = 0; i < g[now].size(); i++) {
if (g[now][i] == par) {
p = 1;
continue;
}
solve(g[now][i], now,
((left[i - p] * right[i + 2 - p]) % M * (pans + 1) % M) % M);
}
}
int main() {
cin >> N >> M;
for (int i = 1; i < N; i++) {
int x, y;
cin >> x >> y;
x--;
y--;
g[x].push_back(y);
g[y].push_back(x);
}
ans[0] = dfs(0, 0);
solve(0, -1, 0);
for (int i = 0; i < N; i++)
cout << ans[i] << endl;
return 0;
}
| #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define MOD 1000000007
typedef long long ll;
using namespace std;
int N, M;
vector<int> g[100010];
ll dp[100010];
ll ans[100010];
vector<ll> child[100010];
ll dfs(int now, int par) {
ll res = 1;
for (int nex : g[now]) {
if (nex == par)
continue;
ll z = dfs(nex, now);
child[now].push_back(z);
res = res * (z + 1) % M;
}
res = (res + M) % M;
return dp[now] = res;
}
void solve(int now, int par, ll pans) {
if (par != -1) {
ll res = pans + 1;
for (int i = 0; i < child[now].size(); i++) {
res = (res * (child[now][i] + 1)) % M;
}
ans[now] = res;
}
int n = child[now].size();
vector<ll> left(n + 2), right(n + 2);
left[0] = 1;
right[n + 1] = 1;
for (int i = 1; i <= n; i++)
left[i] = (left[i - 1] * (child[now][i - 1] + 1) % M) % M;
for (int i = n; i >= 1; i--)
right[i] = (right[i + 1] * (child[now][i - 1] + 1) % M) % M;
int p = 0;
for (int i = 0; i < g[now].size(); i++) {
if (g[now][i] == par) {
p = 1;
continue;
}
solve(g[now][i], now,
((left[i - p] * right[i + 2 - p]) % M * (pans + 1) % M) % M);
}
}
int main() {
cin >> N >> M;
for (int i = 1; i < N; i++) {
int x, y;
cin >> x >> y;
x--;
y--;
g[x].push_back(y);
g[y].push_back(x);
}
ans[0] = dfs(0, 0);
solve(0, -1, 0);
for (int i = 0; i < N; i++)
cout << (ans[i] + M) % M << endl;
return 0;
}
| [
"expression.operation.binary.add"
] | 987,045 | 987,047 | u646339490 | cpp |
p03181 | #include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;
vi adj[100001];
int n, mod;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int sub(int a, int b) { return (a -= b) >= 0 ? a : a + mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }
void adds(int &a, int b) { a = add(a, b); }
void subs(int &a, int b) { a = sub(a, b); }
void muls(int &a, int b) { a = mul(a, b); }
void maxs(int &a, int b) { a = max(a, b); }
void mins(int &a, int b) { a = min(a, b); }
int pwr(int a, ll p) {
if (p == 0)
return 1;
if (p & 1)
return mul(a, pwr(a, p - 1));
return pwr(mul(a, a), p / 2);
}
int inv(int a) { return pwr(a, mod - 2); }
int dp[100001];
int dfs(int x, int p = -1) {
if (dp[x] != -1)
return dp[x];
int sol = 1;
for (int y : adj[x])
if (y != p)
muls(sol, add(1, dfs(y, x)));
return dp[x] = sol;
}
int dp2[100001];
void dfs2(int x, int p = -1, int f = 0) {
int sz = adj[x].size() - int(p != -1), i = 0;
vi pref(sz), suff(sz);
for (int y : adj[x])
if (y != p)
pref[i] = suff[i] = add(1, dp[y]), ++i;
for (int i = 1; i < sz; ++i)
muls(pref[i], pref[i - 1]);
for (int i = sz - 2; i >= 0; --i)
muls(suff[i], suff[i + 1]);
i = 0;
for (int y : adj[x]) {
if (y == p)
continue;
int g = add(f, 1);
if (i != 0)
muls(g, pref[i - 1]);
if (i != sz - 1)
muls(g, suff[i + 1]);
dfs2(y, x, g);
}
dp2[x] = mul(add(f, 1), dp[x]);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> mod;
for (int i = 0; i < n - 1; ++i) {
int x, y;
cin >> x >> y;
adj[x].push_back(y);
adj[y].push_back(x);
}
memset(dp, -1, sizeof dp);
dfs(1);
dfs2(1);
for (int i = 1; i <= n; ++i)
cout << dp2[i] << '\n';
}
| #include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;
vi adj[100001];
int n, mod;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int sub(int a, int b) { return (a -= b) >= 0 ? a : a + mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }
void adds(int &a, int b) { a = add(a, b); }
void subs(int &a, int b) { a = sub(a, b); }
void muls(int &a, int b) { a = mul(a, b); }
void maxs(int &a, int b) { a = max(a, b); }
void mins(int &a, int b) { a = min(a, b); }
int pwr(int a, ll p) {
if (p == 0)
return 1;
if (p & 1)
return mul(a, pwr(a, p - 1));
return pwr(mul(a, a), p / 2);
}
int inv(int a) { return pwr(a, mod - 2); }
int dp[100001];
int dfs(int x, int p = -1) {
if (dp[x] != -1)
return dp[x];
int sol = 1;
for (int y : adj[x])
if (y != p)
muls(sol, add(1, dfs(y, x)));
return dp[x] = sol;
}
int dp2[100001];
void dfs2(int x, int p = -1, int f = 0) {
int sz = adj[x].size() - int(p != -1), i = 0;
vi pref(sz), suff(sz);
for (int y : adj[x])
if (y != p)
pref[i] = suff[i] = add(1, dp[y]), ++i;
for (int i = 1; i < sz; ++i)
muls(pref[i], pref[i - 1]);
for (int i = sz - 2; i >= 0; --i)
muls(suff[i], suff[i + 1]);
i = 0;
for (int y : adj[x]) {
if (y == p)
continue;
int g = add(f, 1);
if (i != 0)
muls(g, pref[i - 1]);
if (i != sz - 1)
muls(g, suff[i + 1]);
dfs2(y, x, g);
++i;
}
dp2[x] = mul(add(f, 1), dp[x]);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> mod;
for (int i = 0; i < n - 1; ++i) {
int x, y;
cin >> x >> y;
adj[x].push_back(y);
adj[y].push_back(x);
}
memset(dp, -1, sizeof dp);
dfs(1);
dfs2(1);
for (int i = 1; i <= n; ++i)
cout << dp2[i] << '\n';
}
| [
"expression.unary.arithmetic.add"
] | 987,048 | 987,049 | u562319622 | cpp |
p03181 | #include "bits/stdc++.h"
#define ALL(g) (g).begin(), (g).end()
#define REP(i, x, n) for (int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define RREP(i, x, n) for (int i = x; i >= n; i--)
#define rrep(i, n) RREP(i, n, 0)
#define pb push_back
#pragma GCC optimize("-O3")
using namespace std;
// #define DEBUG_IS_VALID
#ifdef DEBUG_IS_VALID
#define DEB 1
#else
#define DEB 0
#endif
#define DUMPOUT cout
#define dump(...) \
if (DEB) \
DUMPOUT << " " << #__VA_ARGS__ << " :[" << __LINE__ << ":" \
<< __FUNCTION__ << "]" << endl \
<< " "; \
if (DEB) \
dump_func(__VA_ARGS__)
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
cout << "(" << p.first << ", " << p.second << ")";
return os;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
os << "{";
for (int i = 0; i < vec.size(); i++)
os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
os << "}";
return os;
}
template <typename T> ostream &operator<<(ostream &os, set<T> &st) {
cout << "{";
for (auto itr = st.begin(); itr != st.end(); itr++)
cout << *itr << (next(itr) != st.end() ? ", " : "");
cout << "}";
return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> mp) {
cout << "{";
for (auto itr = mp.begin(); itr != mp.end(); itr++)
cout << "(" << (itr->first) << ", " << (itr->second) << ")"
<< (next(itr) != mp.end() ? "," : "");
cout << "}";
return os;
}
void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&...tail) {
DUMPOUT << head;
if (sizeof...(Tail) == 0) {
DUMPOUT << " ";
} else {
DUMPOUT << ", ";
}
dump_func(std::move(tail)...);
}
template <class T> inline bool chmax(T &a, T const &b) {
if (a >= b)
return false;
a = b;
return true;
}
template <class T> inline bool chmin(T &a, T const &b) {
if (a <= b)
return false;
a = b;
return true;
}
void _main();
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
_main();
return 0;
}
using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
const int mod = 1e9 + 7, INF = 1 << 29;
const double EPS = 1e-5, PI = 3.1415926535897932384626;
const ll lmod = 1e9 + 7, LINF = 1LL << 59;
template <int MOD> struct ModInt {
static const int Mod = MOD;
unsigned x;
ModInt() : x(0) {}
ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
int get() const { return (int)x; }
ModInt &operator+=(ModInt that) {
if ((x += that.x) >= MOD)
x -= MOD;
return *this;
}
ModInt &operator-=(ModInt that) {
if ((x += MOD - that.x) >= MOD)
x -= MOD;
return *this;
}
ModInt &operator*=(ModInt that) {
x = (unsigned long long)x * that.x % MOD;
return *this;
}
ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
ModInt inverse() const {
long long a = x, b = MOD, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
std::swap(a, b);
u -= t * v;
std::swap(u, v);
}
return ModInt(u);
}
bool operator==(ModInt that) const { return x == that.x; }
bool operator!=(ModInt that) const { return x != that.x; }
ModInt operator-() const {
ModInt t;
t.x = x == 0 ? 0 : Mod - x;
return t;
}
};
template <int MOD> ostream &operator<<(ostream &st, const ModInt<MOD> a) {
st << a.get();
return st;
};
template <int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
ModInt<MOD> r = 1;
while (k) {
if (k & 1)
r *= a;
a *= a;
k >>= 1;
}
return r;
}
template <typename T, int FAC_MAX> struct Comb {
vector<T> fac, ifac;
Comb() {
fac.resize(FAC_MAX, 1);
ifac.resize(FAC_MAX, 1);
for (int i = 1; i < FAC_MAX; i++)
fac[i] = fac[i - 1] * i;
ifac[FAC_MAX - 1] = T(1) / fac[FAC_MAX - 1];
for (int i = FAC_MAX - 2; i >= 1; i--)
ifac[i] = ifac[i + 1] * T(i + 1);
}
T aPb(int a, int b) {
if (b < 0 || a < b)
return T(0);
return fac[a] * ifac[a - b];
}
T aCb(int a, int b) {
if (b < 0 || a < b)
return T(0);
return fac[a] * ifac[a - b] * ifac[b];
}
T nHk(int n, int k) {
if (n == 0 && k == 0)
return T(1);
if (n <= 0 || k < 0)
return 0;
return aCb(n + k - 1, k);
}
}; // nHk = (n+k-1)Ck : n is separator
using mint = ModInt<int(1e9 + 7)>;
using vm = vector<mint>;
void _main() {
int N;
ll M;
cin >> N >> M;
vvi g(N);
rep(i, N - 1) {
int a, b;
cin >> a >> b;
a--;
b--;
g[a].pb(b);
g[b].pb(a);
}
vl dp(N), ans(N);
function<void(int, int)> dfs1 = [&](int u, int p) {
dp[u] = 1;
for (auto v : g[u]) {
if (v == p)
continue;
dfs1(v, u);
(dp[u] *= (dp[v] + 1)) %= M;
}
};
function<void(int, int, ll)> dfs2 = [&](int u, int p, int pval) {
ans[u] = 1;
for (auto v : g[u]) {
if (v == p)
(ans[u] *= pval) %= M;
else
(ans[u] *= (dp[v] + 1)) %= M;
}
int sz = g[u].size();
vl sl(sz + 1, 1), sr(sz + 1, 1);
rep(i, sz) {
int v = g[u][i];
ll val = (i == p ? pval : dp[v] + 1);
(sl[i + 1] = sl[i] * val) %= M;
}
rrep(i, sz - 1) {
int v = g[u][i];
ll val = (i == p ? pval : dp[v] + 1);
(sr[i] = sr[i + 1] * val) %= M;
}
dump(u, pval, sl, sr);
rep(i, sz) {
int v = g[u][i];
if (v == p)
continue;
ll nx = (sl[i] * sr[i + 1] + 1) % M;
dump(v, nx);
dfs2(v, u, nx);
}
};
dfs1(0, -1);
dfs2(0, -1, 1);
dump(dp);
dump(ans);
rep(i, N) cout << ans[i] << endl;
} | #include "bits/stdc++.h"
#define ALL(g) (g).begin(), (g).end()
#define REP(i, x, n) for (int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define RREP(i, x, n) for (int i = x; i >= n; i--)
#define rrep(i, n) RREP(i, n, 0)
#define pb push_back
#pragma GCC optimize("-O3")
using namespace std;
// #define DEBUG_IS_VALID
#ifdef DEBUG_IS_VALID
#define DEB 1
#else
#define DEB 0
#endif
#define DUMPOUT cout
#define dump(...) \
if (DEB) \
DUMPOUT << " " << #__VA_ARGS__ << " :[" << __LINE__ << ":" \
<< __FUNCTION__ << "]" << endl \
<< " "; \
if (DEB) \
dump_func(__VA_ARGS__)
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
cout << "(" << p.first << ", " << p.second << ")";
return os;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
os << "{";
for (int i = 0; i < vec.size(); i++)
os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
os << "}";
return os;
}
template <typename T> ostream &operator<<(ostream &os, set<T> &st) {
cout << "{";
for (auto itr = st.begin(); itr != st.end(); itr++)
cout << *itr << (next(itr) != st.end() ? ", " : "");
cout << "}";
return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> mp) {
cout << "{";
for (auto itr = mp.begin(); itr != mp.end(); itr++)
cout << "(" << (itr->first) << ", " << (itr->second) << ")"
<< (next(itr) != mp.end() ? "," : "");
cout << "}";
return os;
}
void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&...tail) {
DUMPOUT << head;
if (sizeof...(Tail) == 0) {
DUMPOUT << " ";
} else {
DUMPOUT << ", ";
}
dump_func(std::move(tail)...);
}
template <class T> inline bool chmax(T &a, T const &b) {
if (a >= b)
return false;
a = b;
return true;
}
template <class T> inline bool chmin(T &a, T const &b) {
if (a <= b)
return false;
a = b;
return true;
}
void _main();
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
_main();
return 0;
}
using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
const int mod = 1e9 + 7, INF = 1 << 29;
const double EPS = 1e-5, PI = 3.1415926535897932384626;
const ll lmod = 1e9 + 7, LINF = 1LL << 59;
template <int MOD> struct ModInt {
static const int Mod = MOD;
unsigned x;
ModInt() : x(0) {}
ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
int get() const { return (int)x; }
ModInt &operator+=(ModInt that) {
if ((x += that.x) >= MOD)
x -= MOD;
return *this;
}
ModInt &operator-=(ModInt that) {
if ((x += MOD - that.x) >= MOD)
x -= MOD;
return *this;
}
ModInt &operator*=(ModInt that) {
x = (unsigned long long)x * that.x % MOD;
return *this;
}
ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
ModInt inverse() const {
long long a = x, b = MOD, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
std::swap(a, b);
u -= t * v;
std::swap(u, v);
}
return ModInt(u);
}
bool operator==(ModInt that) const { return x == that.x; }
bool operator!=(ModInt that) const { return x != that.x; }
ModInt operator-() const {
ModInt t;
t.x = x == 0 ? 0 : Mod - x;
return t;
}
};
template <int MOD> ostream &operator<<(ostream &st, const ModInt<MOD> a) {
st << a.get();
return st;
};
template <int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
ModInt<MOD> r = 1;
while (k) {
if (k & 1)
r *= a;
a *= a;
k >>= 1;
}
return r;
}
template <typename T, int FAC_MAX> struct Comb {
vector<T> fac, ifac;
Comb() {
fac.resize(FAC_MAX, 1);
ifac.resize(FAC_MAX, 1);
for (int i = 1; i < FAC_MAX; i++)
fac[i] = fac[i - 1] * i;
ifac[FAC_MAX - 1] = T(1) / fac[FAC_MAX - 1];
for (int i = FAC_MAX - 2; i >= 1; i--)
ifac[i] = ifac[i + 1] * T(i + 1);
}
T aPb(int a, int b) {
if (b < 0 || a < b)
return T(0);
return fac[a] * ifac[a - b];
}
T aCb(int a, int b) {
if (b < 0 || a < b)
return T(0);
return fac[a] * ifac[a - b] * ifac[b];
}
T nHk(int n, int k) {
if (n == 0 && k == 0)
return T(1);
if (n <= 0 || k < 0)
return 0;
return aCb(n + k - 1, k);
}
}; // nHk = (n+k-1)Ck : n is separator
using mint = ModInt<int(1e9 + 7)>;
using vm = vector<mint>;
void _main() {
int N;
ll M;
cin >> N >> M;
vvi g(N);
rep(i, N - 1) {
int a, b;
cin >> a >> b;
a--;
b--;
g[a].pb(b);
g[b].pb(a);
}
vl dp(N), ans(N);
function<void(int, int)> dfs1 = [&](int u, int p) {
dp[u] = 1;
for (auto v : g[u]) {
if (v == p)
continue;
dfs1(v, u);
(dp[u] *= (dp[v] + 1)) %= M;
}
};
function<void(int, int, ll)> dfs2 = [&](int u, int p, int pval) {
ans[u] = 1;
for (auto v : g[u]) {
if (v == p)
(ans[u] *= pval) %= M;
else
(ans[u] *= (dp[v] + 1)) %= M;
}
int sz = g[u].size();
vl sl(sz + 1, 1), sr(sz + 1, 1);
rep(i, sz) {
int v = g[u][i];
ll val = (v == p ? pval : dp[v] + 1);
(sl[i + 1] = sl[i] * val) %= M;
}
rrep(i, sz - 1) {
int v = g[u][i];
ll val = (v == p ? pval : dp[v] + 1);
(sr[i] = sr[i + 1] * val) %= M;
}
dump(u, pval, sl, sr);
rep(i, sz) {
int v = g[u][i];
if (v == p)
continue;
ll nx = (sl[i] * sr[i + 1] + 1) % M;
dump(v, nx);
dfs2(v, u, nx);
}
};
dfs1(0, -1);
dfs2(0, -1, 1);
dump(dp);
dump(ans);
rep(i, N) cout << ans[i] << endl;
} | [
"identifier.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 987,065 | 987,066 | u584355711 | cpp |
p03181 | #include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define pb emplace_back
typedef long long ll;
typedef pair<int, int> pint;
int n, M;
vector<int> g[100001];
ll dp[100001], ans[100001];
ll dfs(int v, int p) {
dp[v] = 1;
rep(i, g[v].size()) if (g[v][i] != p) {
dp[v] *= dfs(g[v][i], v) + 1;
dp[v] %= M;
}
return dp[v];
}
void dfs2(int v, int p) {
int sz = g[v].size();
vector<ll> l(sz), r(sz);
rep(i, sz) {
l[i] = dp[g[v][i]] + 1;
r[i] = l[i];
}
rep(i, sz - 1) l[i + 1] *= l[i], l[i + 1] %= M;
for (int i = sz - 2; i >= 0; --i)
r[i] *= r[i + 1], r[i] %= M;
if (sz >= 1)
ans[v] = l[sz - 1];
else
ans[v] = 1;
rep(i, sz) if (g[v][i] != p) {
dp[v] = 1;
if (i != 0)
dp[v] *= l[i - 1], dp[v] %= M;
if (i + 1 < sz)
dp[v] *= r[i + 1], dp[v] %= M;
dfs2(g[v][i], v);
}
}
int main() {
cin >> n >> M;
int xi, yi;
rep(i, n - 1) {
cin >> xi >> yi;
--xi, --yi;
g[xi].pb(yi);
g[yi].pb(xi);
}
dfs(0, -1);
dfs2(0, -1);
rep(i, n) cout << ans[i] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define pb emplace_back
typedef long long ll;
typedef pair<int, int> pint;
int n, M;
vector<int> g[100001];
ll dp[100001], ans[100001];
ll dfs(int v, int p) {
dp[v] = 1;
rep(i, g[v].size()) if (g[v][i] != p) {
dp[v] *= dfs(g[v][i], v) + 1;
dp[v] %= M;
}
return dp[v];
}
void dfs2(int v, int p) {
int sz = g[v].size();
vector<ll> l(sz), r(sz);
rep(i, sz) {
l[i] = dp[g[v][i]] + 1;
r[i] = l[i];
}
rep(i, sz - 1) l[i + 1] *= l[i], l[i + 1] %= M;
for (int i = sz - 2; i >= 0; --i)
r[i] *= r[i + 1], r[i] %= M;
if (sz >= 1)
ans[v] = l[sz - 1];
else
ans[v] = 1;
rep(i, sz) if (g[v][i] != p) {
dp[v] = 1;
if (i != 0)
dp[v] *= l[i - 1], dp[v] %= M;
if (i + 1 < sz)
dp[v] *= r[i + 1], dp[v] %= M;
dfs2(g[v][i], v);
}
}
int main() {
cin >> n >> M;
int xi, yi;
rep(i, n - 1) {
cin >> xi >> yi;
--xi, --yi;
g[xi].pb(yi);
g[yi].pb(xi);
}
dfs(0, -1);
dfs2(0, -1);
rep(i, n) cout << ans[i] % M << endl;
return 0;
}
| [
"expression.operation.binary.add"
] | 987,089 | 987,090 | u526367939 | cpp |
p03181 | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string.h>
#include <string>
#include <string>
#include <type_traits>
#include <vector>
#define int long long
#define ll long long
#define mod 1000000007
#define MOD 1000000007
#define inf 1e17
#define rep(i, j, n) for (int i = j; i < n; i++)
#define P pair<int, int>
#define ps push_back
#define all(x) x.begin(), x.end()
double pi = 3.141592653589793;
using namespace std;
//ここから始めよう
int n, m;
vector<int> v[114514];
int dp[114514];
int dp2[114514];
int fact(int x, int y) {
if (y == 0)
return 1;
else if (y == 1)
return x;
else if (y % 2 == 0)
return fact(x * x % m, y / 2) % m;
else
return fact(x * x % m, y / 2) % m * x % m;
}
int dfs(int i, int par) {
int &res = dp[i];
if (~res)
return res;
res = 1;
for (auto e : v[i]) {
if (e == par)
continue;
(res *= dfs(e, i) + 1) %= m;
}
return res;
}
vector<int> front[114514], back[114114];
void dfs2(int i, int par, int carry) {
dp2[i] = carry * dp[i] % m;
int h = v[i].size();
front[i].resize(h + 2);
back[i].resize(h + 2);
front[i][0] = 1;
rep(j, 0, n) {
if (v[i][j] == par)
front[i][j + 1] = front[i][j];
else
front[i][j + 1] = front[i][j] * (dp[v[i][j]] + 1) % m;
}
back[i][h + 1] = 1;
for (int j = h; j >= 1; j--) {
if (v[i][j - 1] == par)
back[i][j] = back[i][j + 1];
else
back[i][j] = back[i][j + 1] * (dp[v[i][j - 1]] + 1) % m;
}
// cout<<"Find"<<endl;
for (int j = 0; j < v[i].size(); j++) {
if (v[i][j] == par)
continue;
int k = front[i][j] * back[i][j + 2] % m * carry % m;
dfs2(v[i][j], i, k + 1);
}
}
signed main() {
cin >> n >> m;
if (n == 1) {
cout << 1 << endl;
return 0;
}
rep(i, 0, n - 1) {
int a, b;
cin >> a >> b;
a--;
b--;
v[a].ps(b);
v[b].ps(a);
}
fill(dp, dp + n, -1);
dfs(0, -1);
dfs2(0, -1, 1);
rep(i, 0, n) cout << dp2[i] << endl;
return 0;
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string.h>
#include <string>
#include <type_traits>
#include <vector>
#define int long long
#define ll long long
#define mod 1000000007
#define MOD 1000000007
#define inf 1e17
#define rep(i, j, n) for (int i = j; i < n; i++)
#define P pair<int, int>
#define ps push_back
#define all(x) x.begin(), x.end()
double pi = 3.141592653589793;
using namespace std;
//ここから始めよう
int n, m;
vector<int> v[114514];
int dp[114514];
int dp2[114514];
int fact(int x, int y) {
if (y == 0)
return 1;
else if (y == 1)
return x;
else if (y % 2 == 0)
return fact(x * x % m, y / 2) % m;
else
return fact(x * x % m, y / 2) % m * x % m;
}
int dfs(int i, int par) {
int &res = dp[i];
if (~res)
return res;
res = 1;
for (auto e : v[i]) {
if (e == par)
continue;
(res *= dfs(e, i) + 1) %= m;
}
return res;
}
vector<int> front[114514], back[114114];
void dfs2(int i, int par, int carry) {
dp2[i] = carry * dp[i] % m;
int h = v[i].size();
front[i].resize(h + 2);
back[i].resize(h + 2);
front[i][0] = 1;
rep(j, 0, h) {
if (v[i][j] == par)
front[i][j + 1] = front[i][j];
else
front[i][j + 1] = front[i][j] * (dp[v[i][j]] + 1) % m;
}
back[i][h + 1] = 1;
for (int j = h; j >= 1; j--) {
if (v[i][j - 1] == par)
back[i][j] = back[i][j + 1];
else
back[i][j] = back[i][j + 1] * (dp[v[i][j - 1]] + 1) % m;
}
// cout<<"Find"<<endl;
for (int j = 0; j < v[i].size(); j++) {
if (v[i][j] == par)
continue;
int k = front[i][j] * back[i][j + 2] % m * carry % m;
dfs2(v[i][j], i, k + 1);
}
}
signed main() {
cin >> n >> m;
if (n == 1) {
cout << 1 << endl;
return 0;
}
rep(i, 0, n - 1) {
int a, b;
cin >> a >> b;
a--;
b--;
v[a].ps(b);
v[b].ps(a);
}
fill(dp, dp + n, -1);
dfs(0, -1);
dfs2(0, -1, 1);
rep(i, 0, n) cout << dp2[i] << endl;
return 0;
} | [
"identifier.change",
"call.arguments.change"
] | 987,091 | 987,092 | u318857467 | cpp |
p03181 | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
int read() {
int x = 0, f = 1;
char c = getchar();
while (!isdigit(c)) {
if (c == '-')
f = 0;
c = getchar();
}
while (isdigit(c)) {
x = (x << 3) + (x << 1) + (c ^ 48);
c = getchar();
}
return f ? x : -x;
}
typedef long long LL;
#define int long long
const int maxn = 1e5 + 10, maxm = maxn << 1;
int mod, to[maxm], nxt[maxm], head[maxn], e, f[maxn], g[maxn], ans[maxn],
p[maxn];
vector<int> vec[maxn];
void add(int x, int y) {
to[++e] = y;
nxt[e] = head[x];
head[x] = e;
to[++e] = x;
nxt[e] = head[y];
head[y] = e;
}
void dfs(int u, int fa) {
f[u] = 1;
int tot = 0;
for (int i = head[u]; i; i = nxt[i]) {
int v = to[i];
if (v == fa)
continue;
dfs(v, u);
f[u] = (LL)f[u] * (f[v] + 1) % mod;
p[v] = tot++;
vec[u].push_back(f[v]);
}
}
void dp(int u, int fa) {
vec[u].push_back(g[u]);
for (int i = (int)vec[u].size() - 2; i >= 0; --i)
vec[u][i] = (LL)(vec[u][i] + 1) * vec[u][i + 1] % mod;
int now = 1;
ans[u] = (LL)(g[u] + 1) * f[u] % mod;
for (int i = head[u]; i; i = nxt[i]) {
int v = to[i];
if (v == fa)
continue;
g[v] = ((LL)now * vec[u][p[v] + 1] % mod + 1) % mod;
dp(v, u);
now = (LL)now * (f[v] + 1) % mod;
}
}
main() {
int n = read();
mod = read();
for (int i = 2; i <= n; ++i)
add(read(), read());
dfs(1, 0);
dp(1, 0);
for (int i = 1; i <= n; ++i)
printf("%lld\n", ans[i]);
return 0;
} | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
int read() {
int x = 0, f = 1;
char c = getchar();
while (!isdigit(c)) {
if (c == '-')
f = 0;
c = getchar();
}
while (isdigit(c)) {
x = (x << 3) + (x << 1) + (c ^ 48);
c = getchar();
}
return f ? x : -x;
}
typedef long long LL;
#define int long long
const int maxn = 1e5 + 10, maxm = maxn << 1;
int mod, to[maxm], nxt[maxm], head[maxn], e, f[maxn], g[maxn], ans[maxn],
p[maxn];
vector<int> vec[maxn];
void add(int x, int y) {
to[++e] = y;
nxt[e] = head[x];
head[x] = e;
to[++e] = x;
nxt[e] = head[y];
head[y] = e;
}
void dfs(int u, int fa) {
f[u] = 1;
int tot = 0;
for (int i = head[u]; i; i = nxt[i]) {
int v = to[i];
if (v == fa)
continue;
dfs(v, u);
f[u] = (LL)f[u] * (f[v] + 1) % mod;
p[v] = tot++;
vec[u].push_back(f[v]);
}
}
void dp(int u, int fa) {
vec[u].push_back(g[u] + 1);
for (int i = (int)vec[u].size() - 2; i >= 0; --i)
vec[u][i] = (LL)(vec[u][i] + 1) * vec[u][i + 1] % mod;
int now = 1;
ans[u] = (LL)(g[u] + 1) * f[u] % mod;
for (int i = head[u]; i; i = nxt[i]) {
int v = to[i];
if (v == fa)
continue;
g[v] = ((LL)now * vec[u][p[v] + 1] % mod);
dp(v, u);
now = (LL)now * (f[v] + 1) % mod;
}
}
main() {
int n = read();
mod = read();
for (int i = 2; i <= n; ++i)
add(read(), read());
dfs(1, 0);
dp(1, 0);
for (int i = 1; i <= n; ++i)
printf("%lld\n", ans[i]);
return 0;
} | [
"expression.operation.binary.remove"
] | 987,096 | 987,097 | u066598563 | cpp |
p03181 | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORE(x, xs) for (auto &x : xs)
const int MAX = 1e5 + 10;
const int ROOT = 0;
int N, MOD;
vi G[MAX], child[MAX];
ll dp1[MAX]; // dp1[v]:0を根としたとき、vを黒としたときのvより下の場合の数
ll dp2[MAX]; // dp2[v]:0を根としたとき、vを黒としてvより下が全部白の時の場合の数
vi mult1[MAX]; // mult1[v][i]:vの子jのdp1[j]を小さい方からi-1までかけたもの
vi mult2[MAX]; // mult2[v][i];vの子jのdp1[j]を大きい方からi+1までかけたもの
int parent[MAX];
int num[MAX]; // num[v]:vがparent[v]の何番目の子
void dfs1(int v, int p) {
parent[v] = p;
dp1[v] = 1;
int count = 0;
FORE(x, G[v]) {
if (x == p)
continue;
dfs1(x, v);
(dp1[v] *= dp1[x] + 1) %= MOD;
child[v].push_back(x);
num[x] = count++;
}
}
void calcMult(int v) {
if (child[v].size() == 0)
return;
mult1[v] = mult2[v] = vi(child[v].size());
mult1[v][0] = 1;
REP(i, child[v].size() - 1) {
(mult1[v][i + 1] = mult1[v][i] * (dp1[child[v][i]] + 1)) %= MOD;
}
mult2[v][child[v].size() - 1] = 1;
REPR(i, child[v].size() - 1) {
(mult2[v][i] = mult2[v][i + 1] * (dp1[child[v][i]] + 1)) %= MOD;
}
FORE(x, child[v]) calcMult(x);
}
void dfs2(int v) {
dp2[v] = 1;
if (parent[v] != v) {
int p = parent[v], c = num[v];
dp2[v] = (dp2[p] * (mult1[p][c] * mult2[p][c] % MOD) + 1) % MOD;
}
FORE(x, child[v]) dfs2(x);
}
int main() {
cin >> N >> MOD;
REP(i, N - 1) {
int x, y;
cin >> x >> y;
x--;
y--;
G[x].push_back(y);
G[y].push_back(x);
}
dfs1(ROOT, ROOT);
calcMult(ROOT);
dfs2(ROOT);
REP(i, N) cout << dp1[i] * dp2[i] % MOD << endl;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORE(x, xs) for (auto &x : xs)
const int MAX = 1e5 + 10;
const int ROOT = 0;
int N, MOD;
vi G[MAX], child[MAX];
ll dp1[MAX]; // dp1[v]:0を根としたとき、vを黒としたときのvより下の場合の数
ll dp2[MAX]; // dp2[v]:0を根としたとき、vを黒としてvより下が全部白の時の場合の数
vi mult1[MAX]; // mult1[v][i]:vの子jのdp1[j]を小さい方からi-1までかけたもの
vi mult2[MAX]; // mult2[v][i];vの子jのdp1[j]を大きい方からi+1までかけたもの
int parent[MAX];
int num[MAX]; // num[v]:vがparent[v]の何番目の子
void dfs1(int v, int p) {
parent[v] = p;
dp1[v] = 1;
int count = 0;
FORE(x, G[v]) {
if (x == p)
continue;
dfs1(x, v);
(dp1[v] *= dp1[x] + 1) %= MOD;
child[v].push_back(x);
num[x] = count++;
}
}
void calcMult(int v) {
if (child[v].size() == 0)
return;
mult1[v] = mult2[v] = vi(child[v].size());
mult1[v][0] = 1;
REP(i, child[v].size() - 1) {
(mult1[v][i + 1] = mult1[v][i] * (dp1[child[v][i]] + 1)) %= MOD;
}
mult2[v][child[v].size() - 1] = 1;
REPR(i, child[v].size() - 1) {
(mult2[v][i] = mult2[v][i + 1] * (dp1[child[v][i + 1]] + 1)) %= MOD;
}
FORE(x, child[v]) calcMult(x);
}
void dfs2(int v) {
dp2[v] = 1;
if (parent[v] != v) {
int p = parent[v], c = num[v];
dp2[v] = (dp2[p] * (mult1[p][c] * mult2[p][c] % MOD) + 1) % MOD;
}
FORE(x, child[v]) dfs2(x);
}
int main() {
cin >> N >> MOD;
REP(i, N - 1) {
int x, y;
cin >> x >> y;
x--;
y--;
G[x].push_back(y);
G[y].push_back(x);
}
dfs1(ROOT, ROOT);
calcMult(ROOT);
dfs2(ROOT);
REP(i, N) cout << dp1[i] * dp2[i] % MOD << endl;
} | [
"assignment.change"
] | 987,098 | 987,099 | u957084285 | cpp |
p03181 | #include <bits/stdc++.h>
using namespace std;
#define int long long
inline long long in() {
long long x = 0;
char c = getchar();
bool neg = false;
while (c != '-' && ('0' > c || c > '9'))
c = getchar();
if (c == '-')
neg = true, c = getchar();
while ('0' <= c && c <= '9')
x = 10 * x + c - '0', c = getchar();
if (neg)
x = -x;
return x;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l, int r) { return l + rng() % (r - l + 1); }
#define fasty ios_base::sync_with_stdio(false), cin.tie(nullptr);
#define task "V"
#define forinc(a, b, c) for (int a = b, _c = c; a <= _c; ++a)
#define fordec(a, b, c) for (int a = b, _c = c; a >= _c; --a)
#define forv(a, b) for (auto &a : b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int, int>
#define mt make_tuple
#define all(a) a.begin(), a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define bit(x, i) ((x >> (i - 1)) & 1)
#define on(x, i) (x | (1ll << (i - 1)))
#define off(x, i) (x & ~(1 << (i - 1)))
const int N = 100010;
int n, m, cnt, M;
int f[N], g[N];
vector<int> ad[N];
void dfs1(int u, int p) {
forv(v, ad[u]) if (v != p) dfs1(v, u), f[u] = f[u] * (f[v] + 1) % M;
}
void dfs2(int u, int p) {
m = 0, cnt = 0;
vector<int> a, l, r;
forv(v, ad[u]) if (v != p) cnt++;
a.reserve(cnt + 1);
l.reserve(cnt + 1);
r.reserve(cnt + 1);
forv(v, ad[u]) if (v != p) a[++m] = v;
l[0] = r[m + 1] = 1;
forinc(i, 1, m) l[i] = l[i - 1] * (f[a[i]] + 1) % M;
fordec(i, m, 1) r[i] = r[i + 1] * (f[a[i]] + 1) % M;
forinc(i, 1, m) {
int v = a[i];
g[v] = (g[u] * l[i - 1] % M * r[i + 1] % M + 1) % M;
dfs2(v, u);
}
}
main() {
fasty;
cin >> n >> M;
forinc(i, 2, n) {
int u, v;
cin >> u >> v;
ad[u].pb(v);
ad[v].pb(u);
}
forinc(i, 1, n) f[i] = g[i] = 1;
dfs1(1, 1);
dfs2(1, 1);
forinc(i, 1, n) cout << f[i] * g[i] % M << "\n";
}
/**
we have to re-root the tree, as for every node, we will have to print out
the numbers of way to paint the tree. As the root is colored black, and every
black nodes must be connected, we define F[u] : numbers of ways to color the
subtree of u if node u is black, then the answer for each 'node' is F['node']
after the re-root
If we only have to output the answer for only a node, the dp works like this
F[u] = product of (F[v] + 1) for each direct-child v of u
F[v] : numbers of ways to color the subtree black and
1 : leave it white
now, back to the actual problem
We define G[u] : numbers of ways to colors the nodes out side of u's subtree
with the direct parent of u is colored black So the answer for a 'node' is
F['node'] * (G['node'] + 1) G[u] can be calculated as folows : G[u] = (G[p] +
1) * product of (F[v] + 1) with all v as direct-child of p and v!=u this can
be done O(n) by using partial product
*/
| #include <bits/stdc++.h>
using namespace std;
#define int long long
inline long long in() {
long long x = 0;
char c = getchar();
bool neg = false;
while (c != '-' && ('0' > c || c > '9'))
c = getchar();
if (c == '-')
neg = true, c = getchar();
while ('0' <= c && c <= '9')
x = 10 * x + c - '0', c = getchar();
if (neg)
x = -x;
return x;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l, int r) { return l + rng() % (r - l + 1); }
#define fasty ios_base::sync_with_stdio(false), cin.tie(nullptr);
#define task "V"
#define forinc(a, b, c) for (int a = b, _c = c; a <= _c; ++a)
#define fordec(a, b, c) for (int a = b, _c = c; a >= _c; --a)
#define forv(a, b) for (auto &a : b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int, int>
#define mt make_tuple
#define all(a) a.begin(), a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define bit(x, i) ((x >> (i - 1)) & 1)
#define on(x, i) (x | (1ll << (i - 1)))
#define off(x, i) (x & ~(1 << (i - 1)))
const int N = 100010;
int n, m, cnt, M;
int f[N], g[N];
vector<int> ad[N];
void dfs1(int u, int p) {
forv(v, ad[u]) if (v != p) dfs1(v, u), f[u] = f[u] * (f[v] + 1) % M;
}
void dfs2(int u, int p) {
m = 0, cnt = 0;
vector<int> a, l, r;
forv(v, ad[u]) if (v != p) cnt++;
a.reserve(cnt + 5);
l.reserve(cnt + 5);
r.reserve(cnt + 5);
forv(v, ad[u]) if (v != p) a[++m] = v;
l[0] = r[m + 1] = 1;
forinc(i, 1, m) l[i] = l[i - 1] * (f[a[i]] + 1) % M;
fordec(i, m, 1) r[i] = r[i + 1] * (f[a[i]] + 1) % M;
forinc(i, 1, m) {
int v = a[i];
g[v] = (g[u] * l[i - 1] % M * r[i + 1] % M + 1) % M;
dfs2(v, u);
}
}
main() {
fasty;
cin >> n >> M;
forinc(i, 2, n) {
int u, v;
cin >> u >> v;
ad[u].pb(v);
ad[v].pb(u);
}
forinc(i, 1, n) f[i] = g[i] = 1;
dfs1(1, 1);
dfs2(1, 1);
forinc(i, 1, n) cout << f[i] * g[i] % M << "\n";
}
/**
we have to re-root the tree, as for every node, we will have to print out
the numbers of way to paint the tree. As the root is colored black, and every
black nodes must be connected, we define F[u] : numbers of ways to color the
subtree of u if node u is black, then the answer for each 'node' is F['node']
after the re-root
If we only have to output the answer for only a node, the dp works like this
F[u] = product of (F[v] + 1) for each direct-child v of u
F[v] : numbers of ways to color the subtree black and
1 : leave it white
now, back to the actual problem
We define G[u] : numbers of ways to colors the nodes out side of u's subtree
with the direct parent of u is colored black So the answer for a 'node' is
F['node'] * (G['node'] + 1) G[u] can be calculated as folows : G[u] = (G[p] +
1) * product of (F[v] + 1) with all v as direct-child of p and v!=u this can
be done O(n) by using partial product
*/
| [
"literal.number.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 987,135 | 987,136 | u815544868 | cpp |
p03181 | #include <algorithm>
#include <bitset>
#include <ciso646>
#include <cmath>
#include <complex>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop \
char nyaa; \
cin >> nyaa;
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i >= 0; i--)
#define Rep(i, sta, n) for (int i = sta; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define per1(i, n) for (int i = n; i >= 1; i--)
#define Rep1(i, sta, n) for (int i = sta; i <= n; i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef unsigned long long ul;
int n;
ll m;
vector<int> G[1 << 17];
bool used[1 << 17];
ll ans[1 << 17];
ll out[1 << 17];
vector<LP> v[1 << 17];
void dfs(int root) {
used[root] = true;
ans[root] = 1;
rep(j, G[root].size()) {
int to = G[root][j];
if (used[to])
continue;
else {
dfs(to);
(ans[root] *= ans[to] + 1) %= m;
v[root].push_back({ans[to], to});
}
}
}
void q(int root, ll g) {
out[root] = (g + 1) * ans[root] % m;
int len = v[root].size();
vector<ll> sv;
ll pro = 1;
rep(i, len) {
sv.push_back(pro);
pro *= v[root][i].first + 1;
pro %= m;
}
ll cpro = g + 1;
cpro %= m;
per(i, len) {
int to = v[root][i].second;
ll nex = sv[i] * cpro % m;
q(to, nex);
cpro *= v[root][len - 1 - i].first + 1;
cpro %= m;
}
}
int main() {
cin >> n;
cin >> m;
rep(i, n - 1) {
int a, b;
cin >> a >> b;
a--;
b--;
G[a].push_back(b);
G[b].push_back(a);
}
dfs(0);
q(0, 0);
rep(i, n) { cout << out[i] << endl; }
// stop
return 0;
} | #include <algorithm>
#include <bitset>
#include <ciso646>
#include <cmath>
#include <complex>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop \
char nyaa; \
cin >> nyaa;
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i >= 0; i--)
#define Rep(i, sta, n) for (int i = sta; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define per1(i, n) for (int i = n; i >= 1; i--)
#define Rep1(i, sta, n) for (int i = sta; i <= n; i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef unsigned long long ul;
int n;
ll m;
vector<int> G[1 << 17];
bool used[1 << 17];
ll ans[1 << 17];
ll out[1 << 17];
vector<LP> v[1 << 17];
void dfs(int root) {
used[root] = true;
ans[root] = 1;
rep(j, G[root].size()) {
int to = G[root][j];
if (used[to])
continue;
else {
dfs(to);
(ans[root] *= ans[to] + 1) %= m;
v[root].push_back({ans[to], to});
}
}
}
void q(int root, ll g) {
out[root] = (g + 1) * ans[root] % m;
int len = v[root].size();
vector<ll> sv;
ll pro = 1;
rep(i, len) {
sv.push_back(pro);
pro *= v[root][i].first + 1;
pro %= m;
}
ll cpro = g + 1;
cpro %= m;
per(i, len) {
int to = v[root][i].second;
ll nex = sv[i] * cpro % m;
q(to, nex);
cpro *= v[root][i].first + 1;
cpro %= m;
}
}
int main() {
cin >> n;
cin >> m;
rep(i, n - 1) {
int a, b;
cin >> a >> b;
a--;
b--;
G[a].push_back(b);
G[b].push_back(a);
}
dfs(0);
q(0, 0);
rep(i, n) { cout << out[i] << endl; }
// stop
return 0;
} | [
"expression.operation.binary.remove"
] | 987,143 | 987,144 | u294531924 | cpp |
p03181 | #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
vector<int> G[100000];
ll dp[100000], dp2[100000];
ll M;
ll dfs(int v, int par) {
ll t = 1;
for (int to : G[v]) {
if (to == par)
continue;
(t *= (1 + dfs(to, v))) %= M;
}
return dp[v] = t;
}
void dfs2(int v, int par, ll x) {
int n = G[v].size();
vector<ll> child;
vector<ll> L, R;
for (int to : G[v]) {
child.push_back(to);
if (to == par) {
L.push_back(x + 1);
R.push_back(x + 1);
} else {
L.push_back(dp[to] + 1);
R.push_back(dp[to] + 1);
}
}
for (int i = 1; i < n; i++)
(L[i] *= L[i - 1]) %= M;
for (int i = n - 1; i > 0; i--)
(R[i - 1] *= R[i]) %= M;
dp2[v] = L[n - 1];
for (int i = 0; i < n; i++) {
if (child[i] == par)
continue;
ll t = 1;
if (i > 0)
(t *= L[i - 1]) %= M;
if (i + 1 < n)
(t *= R[i + 1]) %= M;
dfs2(child[i], v, t);
}
}
int main() {
int N;
cin >> N >> M;
if (N == 1) {
cout << 1 << endl;
return 0;
}
for (int i = 0; i < N - 1; i++) {
int x, y;
cin >> x >> y;
x--;
y--;
G[x].push_back(y);
G[y].push_back(x);
}
dfs(0, -1);
dfs2(0, -1, 0);
for (int i = 0; i < N; i++)
cout << dp2[i] << endl;
} | #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
vector<int> G[100000];
ll dp[100000], dp2[100000];
ll M;
ll dfs(int v, int par) {
ll t = 1;
for (int to : G[v]) {
if (to == par)
continue;
(t *= (1 + dfs(to, v))) %= M;
}
return dp[v] = t;
}
void dfs2(int v, int par, ll x) {
int n = G[v].size();
vector<ll> child;
vector<ll> L, R;
for (int to : G[v]) {
child.push_back(to);
if (to == par) {
L.push_back(x + 1);
R.push_back(x + 1);
} else {
L.push_back(dp[to] + 1);
R.push_back(dp[to] + 1);
}
}
for (int i = 1; i < n; i++)
(L[i] *= L[i - 1]) %= M;
for (int i = n - 1; i > 0; i--)
(R[i - 1] *= R[i]) %= M;
dp2[v] = L[n - 1] % M;
for (int i = 0; i < n; i++) {
if (child[i] == par)
continue;
ll t = 1;
if (i > 0)
(t *= L[i - 1]) %= M;
if (i + 1 < n)
(t *= R[i + 1]) %= M;
dfs2(child[i], v, t);
}
}
int main() {
int N;
cin >> N >> M;
if (N == 1) {
cout << 1 << endl;
return 0;
}
for (int i = 0; i < N - 1; i++) {
int x, y;
cin >> x >> y;
x--;
y--;
G[x].push_back(y);
G[y].push_back(x);
}
dfs(0, -1);
dfs2(0, -1, 0);
for (int i = 0; i < N; i++)
cout << dp2[i] << endl;
} | [
"assignment.change"
] | 987,145 | 987,146 | u243961437 | cpp |
p03181 | #include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
//#define int ll
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;
typedef complex<double> base;
#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define mp(a, b) make_pair(a, b)
#define modsum(a, b) ((a) + (b) >= M ? (a) + (b)-M : (a) + (b))
#define modsubtract(a, b) ((a) - (b) < 0 ? (a) - (b) + M : (a) - (b))
#define modmultiply(a, b) (((a) * (b)) % M)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for (int i = 0; i < int(n); ++i)
#define cint const int &
#define SZ(a) ((int)((a).size()))
#define watch(x) cout << (#x) << " = " << (x) << endl;
const double PI = 2 * acos(0.0);
const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";
inline void transpose(vector<string> &a) {
int n = a.size();
if (n == 0)
return;
int m = a[0].size();
vector<string> b(m, string(n, ' '));
fori(i, n) fori(j, m) b[j][i] = a[i][j];
a = b;
}
template <class T> inline ostream &operator<<(ostream &out, vector<T> &a) {
out << "{";
fori(i, SZ(a)) out << a[i] << vector<string>{", ", "}"}[i + 1 == SZ(a)];
return out;
}
void smain();
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifdef MAX_HOME
freopen("input.txt", "r", stdin);
clock_t start = clock();
#define cerr cout
#endif
cout << setprecision(12) << fixed;
smain();
#ifdef MAX_HOME
cout << "\n\n\n\n";
cout << "TOTAL EXECUTION TIME: " << float(clock() - start) / CLOCKS_PER_SEC
<< endl;
#endif
}
ll M;
const int N = 1e5 + 9;
vi g[N];
int n;
ll dp_down[N], dp_up[N];
void dfs0(int v, int par) {
dp_down[v] = 1;
for (int to : g[v])
if (to != par) {
dfs0(to, v);
dp_down[v] = (dp_down[v] * (1LL + dp_down[to])) % M;
}
}
void dfs1(int v, int par) {
vl pref(g[v].size());
vl suf(g[v].size());
vl vals(g[v].size());
fori(i, g[v].size()) {
int to = g[v][i];
if (to == par) {
vals[i] = 1;
continue;
}
vals[i] = (dp_down[to] + 1LL) % M;
}
pref[0] = vals[0];
for (int i = 1; i < vals.size(); ++i) {
pref[i] = (pref[i - 1] + vals[i]) % M;
}
suf.back() = vals.back();
for (int i = SZ(vals) - 2; i >= 0; --i) {
suf[i] = (suf[i + 1] + vals[i]) % M;
}
for (int i = 0; i < g[v].size(); ++i) {
int to = g[v][i];
if (to == par)
continue;
dp_up[to] = dp_up[v];
if (i)
dp_up[to] = dp_up[to] * pref[i - 1] % M;
if (i != SZ(g[v]) - 1)
dp_up[to] = dp_up[to] * suf[i + 1] % M;
dp_up[to] = (dp_up[to] + 1) % M;
dfs1(to, v);
}
}
void smain() {
cin >> n >> M;
if (n == 1) {
cout << "1";
return;
}
fori(iter, n - 1) {
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
dfs0(1, -1);
dp_up[1] = 1;
dfs1(1, -1);
fori(i, n) {
int v = i + 1;
cout << dp_down[v] * dp_up[v] % M << "\n";
}
} | #include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
//#define int ll
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;
typedef complex<double> base;
#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define mp(a, b) make_pair(a, b)
#define modsum(a, b) ((a) + (b) >= M ? (a) + (b)-M : (a) + (b))
#define modsubtract(a, b) ((a) - (b) < 0 ? (a) - (b) + M : (a) - (b))
#define modmultiply(a, b) (((a) * (b)) % M)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for (int i = 0; i < int(n); ++i)
#define cint const int &
#define SZ(a) ((int)((a).size()))
#define watch(x) cout << (#x) << " = " << (x) << endl;
const double PI = 2 * acos(0.0);
const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";
inline void transpose(vector<string> &a) {
int n = a.size();
if (n == 0)
return;
int m = a[0].size();
vector<string> b(m, string(n, ' '));
fori(i, n) fori(j, m) b[j][i] = a[i][j];
a = b;
}
template <class T> inline ostream &operator<<(ostream &out, vector<T> &a) {
out << "{";
fori(i, SZ(a)) out << a[i] << vector<string>{", ", "}"}[i + 1 == SZ(a)];
return out;
}
void smain();
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifdef MAX_HOME
freopen("input.txt", "r", stdin);
clock_t start = clock();
#define cerr cout
#endif
cout << setprecision(12) << fixed;
smain();
#ifdef MAX_HOME
cout << "\n\n\n\n";
cout << "TOTAL EXECUTION TIME: " << float(clock() - start) / CLOCKS_PER_SEC
<< endl;
#endif
}
ll M;
const int N = 1e5 + 9;
vi g[N];
int n;
ll dp_down[N], dp_up[N];
void dfs0(int v, int par) {
dp_down[v] = 1;
for (int to : g[v])
if (to != par) {
dfs0(to, v);
dp_down[v] = (dp_down[v] * (1LL + dp_down[to])) % M;
}
}
void dfs1(int v, int par) {
vl pref(g[v].size());
vl suf(g[v].size());
vl vals(g[v].size());
fori(i, g[v].size()) {
int to = g[v][i];
if (to == par) {
vals[i] = 1;
continue;
}
vals[i] = (dp_down[to] + 1LL) % M;
}
pref[0] = vals[0];
for (int i = 1; i < vals.size(); ++i) {
pref[i] = (pref[i - 1] * vals[i]) % M;
}
suf.back() = vals.back();
for (int i = SZ(vals) - 2; i >= 0; --i) {
suf[i] = (suf[i + 1] * vals[i]) % M;
}
for (int i = 0; i < g[v].size(); ++i) {
int to = g[v][i];
if (to == par)
continue;
dp_up[to] = dp_up[v];
if (i)
dp_up[to] = dp_up[to] * pref[i - 1] % M;
if (i != SZ(g[v]) - 1)
dp_up[to] = dp_up[to] * suf[i + 1] % M;
dp_up[to] = (dp_up[to] + 1) % M;
dfs1(to, v);
}
}
void smain() {
cin >> n >> M;
if (n == 1) {
cout << "1";
return;
}
fori(iter, n - 1) {
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
dfs0(1, -1);
dp_up[1] = 1;
dfs1(1, -1);
fori(i, n) {
int v = i + 1;
cout << dp_down[v] * dp_up[v] % M << "\n";
}
} | [
"expression.operator.arithmetic.change",
"assignment.value.change",
"expression.operation.binary.change"
] | 987,149 | 987,150 | u443685186 | cpp |
p03181 | #include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, m, n) for (int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<ll, int> pli;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
// const ll mod=1e9+7 ;
ll dp[101010], ans[101010];
vector<int> v[101010];
ll mod;
struct LazySegmentTree {
private:
int n;
vector<ll> node, lazy;
public:
LazySegmentTree(int sz, ll init = 1) {
n = 1;
while (n < sz)
n *= 2;
node.resize(2 * n - 1, init);
lazy.resize(2 * n - 1, 1);
}
void eval(int k, int l, int r) {
if (lazy[k] != 1)
node[k] = node[k] * lazy[k] % mod;
if (r - l > 1) {
(lazy[2 * k + 1] *= lazy[k]) %= mod;
(lazy[2 * k + 2] *= lazy[k]) %= mod;
}
lazy[k] = 1;
}
//[a,b)にxを加算
void add(int a, int b, ll x, int k = 0, int l = 0, int r = -1) {
if (r < 0)
r = n;
eval(k, l, r);
if (r <= a || b <= l)
return;
if (a <= l && r <= b) {
(lazy[k] *= x) %= mod;
eval(k, l, r);
} else {
add(a, b, x, 2 * k + 1, l, (l + r) / 2);
add(a, b, x, 2 * k + 2, (l + r) / 2, r);
node[k] = node[2 * k + 1] * node[2 * k + 2] % mod;
}
}
//[a,b)での和を返す
ll get(int a, int b, int k = 0, int l = 0, int r = -1) {
if (r < 0)
r = n;
eval(k, l, r);
if (r <= a || b <= l)
return 1;
if (a <= l && r <= b)
return node[k];
ll xl = get(a, b, 2 * k + 1, l, (l + r) / 2);
ll xr = get(a, b, 2 * k + 2, (l + r) / 2, r);
return xl * xr % mod;
}
};
ll dfs1(int x, int p) {
ll ret = 1;
int n = v[x].size();
rep(i, n) {
int to = v[x][i];
if (to == p)
continue;
ll res = dfs1(to, x);
(ret *= (res + 1)) %= mod;
}
dp[x] = ret;
return ret;
}
void dfs2(int x, int p) {
ll ret = ans[x] + 1;
int n = v[x].size();
LazySegmentTree sg(n);
rep(i, n) {
int to = v[x][i];
if (to == p)
continue;
(ret *= (dp[to] + 1)) %= mod;
sg.add(0, i, dp[to] + 1);
sg.add(i + 1, n, dp[to] + 1);
}
sg.add(0, n, ans[x] + 1);
rep(i, n) {
int to = v[x][i];
if (to == p)
continue;
else
ans[to] = sg.get(i, i + 1);
}
for (auto to : v[x]) {
if (to == p)
continue;
dfs2(to, x);
}
ans[x] = ret;
}
int main() {
int n;
cin >> n >> mod;
rep(i, n - 1) {
int x, y;
cin >> x >> y;
--x;
--y;
v[x].push_back(y);
v[y].push_back(x);
}
dfs1(0, -1);
dfs2(0, -1);
rep(i, n) cout << ans[i] << endl;
return 0;
} | #include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, m, n) for (int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<ll, int> pli;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
// const ll mod=1e9+7 ;
ll dp[101010], ans[101010];
vector<int> v[101010];
ll mod;
struct LazySegmentTree {
private:
int n;
vector<ll> node, lazy;
public:
LazySegmentTree(int sz, ll init = 1) {
n = 1;
while (n < sz)
n *= 2;
node.resize(2 * n - 1, init);
lazy.resize(2 * n - 1, 1);
}
void eval(int k, int l, int r) {
if (lazy[k] != 1)
node[k] = node[k] * lazy[k] % mod;
if (r - l > 1) {
(lazy[2 * k + 1] *= lazy[k]) %= mod;
(lazy[2 * k + 2] *= lazy[k]) %= mod;
}
lazy[k] = 1;
}
//[a,b)にxを加算
void add(int a, int b, ll x, int k = 0, int l = 0, int r = -1) {
if (r < 0)
r = n;
eval(k, l, r);
if (r <= a || b <= l)
return;
if (a <= l && r <= b) {
(lazy[k] *= x) %= mod;
eval(k, l, r);
} else {
add(a, b, x, 2 * k + 1, l, (l + r) / 2);
add(a, b, x, 2 * k + 2, (l + r) / 2, r);
node[k] = node[2 * k + 1] * node[2 * k + 2] % mod;
}
}
//[a,b)での和を返す
ll get(int a, int b, int k = 0, int l = 0, int r = -1) {
if (r < 0)
r = n;
eval(k, l, r);
if (r <= a || b <= l)
return 1;
if (a <= l && r <= b)
return node[k];
ll xl = get(a, b, 2 * k + 1, l, (l + r) / 2);
ll xr = get(a, b, 2 * k + 2, (l + r) / 2, r);
return xl * xr % mod;
}
};
ll dfs1(int x, int p) {
ll ret = 1;
int n = v[x].size();
rep(i, n) {
int to = v[x][i];
if (to == p)
continue;
ll res = dfs1(to, x);
(ret *= (res + 1)) %= mod;
}
dp[x] = ret;
return ret;
}
void dfs2(int x, int p) {
ll ret = ans[x] + 1;
int n = v[x].size();
LazySegmentTree sg(n);
rep(i, n) {
int to = v[x][i];
if (to == p)
continue;
(ret *= (dp[to] + 1)) %= mod;
sg.add(0, i, dp[to] + 1);
sg.add(i + 1, n, dp[to] + 1);
}
sg.add(0, n, ans[x] + 1);
rep(i, n) {
int to = v[x][i];
if (to == p)
continue;
else
ans[to] = sg.get(i, i + 1);
}
for (auto to : v[x]) {
if (to == p)
continue;
dfs2(to, x);
}
ans[x] = ret % mod;
}
int main() {
int n;
cin >> n >> mod;
rep(i, n - 1) {
int x, y;
cin >> x >> y;
--x;
--y;
v[x].push_back(y);
v[y].push_back(x);
}
dfs1(0, -1);
dfs2(0, -1);
rep(i, n) cout << ans[i] << endl;
return 0;
} | [
"assignment.change"
] | 987,155 | 987,156 | u352642493 | cpp |
p03181 | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; (i) < (int)(n); (i)++)
using namespace std;
int main() {
int n, m;
scanf("%d%d", &n, &m);
vector<vector<int>> tmp(n);
rep(i, n - 1) {
int a, b;
scanf("%d%d", &a, &b);
a--, b--;
tmp[a].push_back(b);
tmp[b].push_back(a);
}
vector<vector<int>> g(n);
function<void(int, int)> modify = [&](int u, int prev) {
for (auto v : tmp[u])
if (v != prev) {
g[u].push_back(v);
modify(v, u);
}
};
modify(0, -1);
vector<long long> dp(n);
vector<vector<long long>> left(n), right(n);
function<void(int)> dfs = [&](int u) {
for (auto v : g[u]) {
dfs(v);
}
if (g[u].size() == 0) {
dp[u] = 1;
return;
}
dp[u] = 1;
for (auto v : g[u]) {
(dp[u] *= dp[v] + 1) %= m;
}
left[u].resize(g[u].size());
right[u].resize(g[u].size());
left[u][0] = dp[g[u][0]] + 1;
right[u][g[u].size() - 1] = dp[g[u].back()] + 1;
for (int i = 1; i < g[u].size(); i++) {
left[u][i] = left[u][i - 1] * (dp[g[u][i]] + 1) % m;
}
for (int i = (int)g[u].size() - 2; i >= 0; i--) {
right[u][i] = right[u][i + 1] * (dp[g[u][i]] + 1) % m;
}
};
dfs(0);
vector<long long> ans(n);
function<void(int, long long)> dfs2 = [&](int u, long long r) {
ans[u] = dp[u] * (r + 1);
for (int i = 0; i < g[u].size(); i++) {
long long nxt = (i > 0 ? left[u][i - 1] : 1) *
(i < (int)g[u].size() - 1 ? right[u][i + 1] : 1) % m;
dfs2(g[u][i], nxt * (r + 1) % m);
}
};
dfs2(0, 0);
rep(i, n) { printf("%lld\n", ans[i]); }
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; (i) < (int)(n); (i)++)
using namespace std;
int main() {
int n, m;
scanf("%d%d", &n, &m);
vector<vector<int>> tmp(n);
rep(i, n - 1) {
int a, b;
scanf("%d%d", &a, &b);
a--, b--;
tmp[a].push_back(b);
tmp[b].push_back(a);
}
vector<vector<int>> g(n);
function<void(int, int)> modify = [&](int u, int prev) {
for (auto v : tmp[u])
if (v != prev) {
g[u].push_back(v);
modify(v, u);
}
};
modify(0, -1);
vector<long long> dp(n);
vector<vector<long long>> left(n), right(n);
function<void(int)> dfs = [&](int u) {
for (auto v : g[u]) {
dfs(v);
}
if (g[u].size() == 0) {
dp[u] = 1;
return;
}
dp[u] = 1;
for (auto v : g[u]) {
(dp[u] *= dp[v] + 1) %= m;
}
left[u].resize(g[u].size());
right[u].resize(g[u].size());
left[u][0] = dp[g[u][0]] + 1;
right[u][g[u].size() - 1] = dp[g[u].back()] + 1;
for (int i = 1; i < g[u].size(); i++) {
left[u][i] = left[u][i - 1] * (dp[g[u][i]] + 1) % m;
}
for (int i = (int)g[u].size() - 2; i >= 0; i--) {
right[u][i] = right[u][i + 1] * (dp[g[u][i]] + 1) % m;
}
};
dfs(0);
vector<long long> ans(n);
function<void(int, long long)> dfs2 = [&](int u, long long r) {
ans[u] = dp[u] * (r + 1) % m;
for (int i = 0; i < g[u].size(); i++) {
long long nxt = (i > 0 ? left[u][i - 1] : 1) *
(i < (int)g[u].size() - 1 ? right[u][i + 1] : 1) % m;
dfs2(g[u][i], nxt * (r + 1) % m);
}
};
dfs2(0, 0);
rep(i, n) { printf("%lld\n", ans[i]); }
return 0;
}
| [
"assignment.change"
] | 987,167 | 987,168 | u987564901 | cpp |
p03182 | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int maxn = 200010;
const int lo = 20;
const int off = 1 << lo;
const int siz = off * 2;
const long long inf = (1LL << 50);
int n, m;
int a[maxn], b[maxn], c[maxn];
int dp[maxn];
long long tour[siz], prop[siz];
// long long niz[maxn];
vector<pair<long long, int>> niz[maxn];
void send(int node) {
tour[node * 2] += prop[node], tour[node * 2 + 1] += prop[node];
prop[node * 2] += prop[node], prop[node * 2 + 1] += prop[node];
prop[node] = 0;
}
void update(int a, int b, int x, int y, int node, long long val) {
/**
for (int i = a; i <= b; i++)
tour[i] += val;
**/
if (x > b || y < a)
return;
if (x >= a && y <= b) {
tour[node] += val;
prop[node] += val;
// if (node >= off)
return;
}
send(node);
int mid = (x + y) / 2;
update(a, b, x, mid, node * 2, val);
update(a, b, mid + 1, y, node * 2 + 1, val);
tour[node] = max(tour[node * 2], tour[node * 2 + 1]);
}
long long query(int a, int b, int x, int y, int node) {
/**
long long sol = -inf;
for (int i = a; i <= b; i++)
sol = max(tour[i], sol);
return sol;
**/
if (x > b || y < a)
return -inf;
if (x >= a && y <= b)
return tour[node];
send(node);
int mid = (x + y) / 2;
return max(query(a, b, x, mid, node * 2),
query(a, b, mid + 1, y, node * 2 + 1));
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < m; i++)
scanf("%d%d%d", a + i, b + i, c + i);
for (int i = 0; i < m; i++) {
niz[a[i]].push_back(make_pair(c[i], a[i] - 1));
niz[b[i] + 1].push_back(make_pair(-c[i], a[i] - 1));
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j < niz[i].size(); j++)
update(0, niz[i][j].second, 0, off - 1, 1, niz[i][j].first);
dp[i] = query(0, i - 1, 0, off - 1, 1);
update(i, i, 0, off - 1, 1, dp[i]);
// for (int i = 0; i <= n; i++) printf("%d ", tour[i]); printf("\n");
}
// printf("debug: "); for (int i = 1; i <= n; i++) printf("%d ", dp[i]);
// printf("\n");
printf("%lld\n", *max_element(dp + 1, dp + n + 1));
// system("pause");
return 0;
}
| #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int maxn = 200010;
const int lo = 20;
const int off = 1 << lo;
const int siz = off * 2;
const long long inf = (1LL << 50);
int n, m;
int a[maxn], b[maxn], c[maxn];
long long dp[maxn];
long long tour[siz], prop[siz];
// long long niz[maxn];
vector<pair<long long, int>> niz[maxn];
void send(int node) {
tour[node * 2] += prop[node], tour[node * 2 + 1] += prop[node];
prop[node * 2] += prop[node], prop[node * 2 + 1] += prop[node];
prop[node] = 0;
}
void update(int a, int b, int x, int y, int node, long long val) {
/**
for (int i = a; i <= b; i++)
tour[i] += val;
**/
if (x > b || y < a)
return;
if (x >= a && y <= b) {
tour[node] += val;
prop[node] += val;
// if (node >= off)
return;
}
send(node);
int mid = (x + y) / 2;
update(a, b, x, mid, node * 2, val);
update(a, b, mid + 1, y, node * 2 + 1, val);
tour[node] = max(tour[node * 2], tour[node * 2 + 1]);
}
long long query(int a, int b, int x, int y, int node) {
/**
long long sol = -inf;
for (int i = a; i <= b; i++)
sol = max(tour[i], sol);
return sol;
**/
if (x > b || y < a)
return -inf;
if (x >= a && y <= b)
return tour[node];
send(node);
int mid = (x + y) / 2;
return max(query(a, b, x, mid, node * 2),
query(a, b, mid + 1, y, node * 2 + 1));
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < m; i++)
scanf("%d%d%d", a + i, b + i, c + i);
for (int i = 0; i < m; i++) {
niz[a[i]].push_back(make_pair(c[i], a[i] - 1));
niz[b[i] + 1].push_back(make_pair(-c[i], a[i] - 1));
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j < niz[i].size(); j++)
update(0, niz[i][j].second, 0, off - 1, 1, niz[i][j].first);
dp[i] = query(0, i - 1, 0, off - 1, 1);
update(i, i, 0, off - 1, 1, dp[i]);
// for (int i = 0; i <= n; i++) printf("%d ", tour[i]); printf("\n");
}
// printf("debug: "); for (int i = 1; i <= n; i++) printf("%d ", dp[i]);
// printf("\n");
printf("%lld\n", *max_element(dp, dp + n + 1));
// system("pause");
return 0;
}
| [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 987,195 | 987,196 | u943761541 | cpp |
p03182 | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n); i >= 0; i--)
#define loop(i, r, n) for (int i = (r); i < (n); i++)
#define pb push_back
#define all(in) in.begin(), in.end()
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
using ll = long long;
using namespace std;
// 遅延評価セグメント木 lazyRmaxQ
struct lazyRmaxQ {
ll n;
vector<ll> node, lazy;
// 初期化
lazyRmaxQ(int n_) {
int x = 1;
while (x < n_)
x *= 2;
n = x;
node.resize(n * 2 - 1, 0);
lazy.resize(n * 2 - 1, 0);
}
// 遅延評価
void eval(int k, int l, int r) {
if (lazy[k] != 0) {
node[k] += lazy[k];
if (r - l > 1) {
lazy[2 * k + 1] += lazy[k];
lazy[2 * k + 2] += lazy[k];
}
lazy[k] = 0;
}
}
// 値の加算(変更)
void update(int a, int b, ll x, int k = 0, int l = 0, int r = -1) {
if (r == -1)
r = n;
eval(k, l, r);
if (r <= a || b <= l)
return;
else if (a <= l && r <= b) {
lazy[k] = x;
eval(k, l, r);
} else {
update(a, b, x, k * 2 + 1, l, (l + r) / 2);
update(a, b, x, k * 2 + 2, (l + r) / 2, r);
node[k] = max(node[2 * k + 1], node[2 * k + 2]);
}
}
// 区間maxを取得する
ll query(int a, int b, int k = 0, int l = 0, int r = -1) {
if (r == -1)
r = n;
if (r <= a || b <= l)
return 0;
eval(k, l, r);
if (a <= l && r <= b)
return node[k];
else {
ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return max(vl, vr);
}
}
};
int main() {
int n, m;
cin >> n >> m;
vector<vector<pair<ll, ll>>> data(n);
rep(i, m) {
ll l, r, a;
cin >> l >> r >> a;
l--;
r--; // 区間[l,r]にaを加算 0-indexed
data[r].pb(make_pair(l, a));
}
lazyRmaxQ ans(n);
rep(i, n) {
ans.update(i, i + 1, ans.query(0, i + 1));
for (auto p : data[i])
ans.update(p.first, i + 1, p.second);
}
cout << ans.query(0, n) << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n); i >= 0; i--)
#define loop(i, r, n) for (int i = (r); i < (n); i++)
#define pb push_back
#define all(in) in.begin(), in.end()
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
using ll = long long;
using namespace std;
// 遅延評価セグメント木 lazyRmaxQ
struct lazyRmaxQ {
ll n;
vector<ll> node, lazy;
// 初期化
lazyRmaxQ(int n_) {
int x = 1;
while (x < n_)
x *= 2;
n = x;
node.resize(n * 2 - 1, 0);
lazy.resize(n * 2 - 1, 0);
}
// 遅延評価
void eval(int k, int l, int r) {
if (lazy[k] != 0) {
node[k] += lazy[k];
if (r - l > 1) {
lazy[2 * k + 1] += lazy[k];
lazy[2 * k + 2] += lazy[k];
}
lazy[k] = 0;
}
}
// 値の加算(変更)
void update(int a, int b, ll x, int k = 0, int l = 0, int r = -1) {
if (r == -1)
r = n;
eval(k, l, r);
if (r <= a || b <= l)
return;
else if (a <= l && r <= b) {
lazy[k] = x;
eval(k, l, r);
} else {
update(a, b, x, k * 2 + 1, l, (l + r) / 2);
update(a, b, x, k * 2 + 2, (l + r) / 2, r);
node[k] = max(node[2 * k + 1], node[2 * k + 2]);
}
}
// 区間maxを取得する
ll query(int a, int b, int k = 0, int l = 0, int r = -1) {
if (r == -1)
r = n;
if (r <= a || b <= l)
return 0;
eval(k, l, r);
if (a <= l && r <= b)
return node[k];
else {
ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return max(vl, vr);
}
}
};
int main() {
int n, m;
cin >> n >> m;
vector<vector<pair<ll, ll>>> data(n);
rep(i, m) {
ll l, r, a;
cin >> l >> r >> a;
l--;
r--; // 区間[l,r]にaを加算 0-indexed
data[r].pb(make_pair(l, a));
}
lazyRmaxQ ans(n);
rep(i, n) {
ans.update(i, i + 1, ans.query(0, i + 1));
for (auto p : data[i])
ans.update(p.first, i + 1, p.second);
}
cout << max(0ll, ans.query(0, n)) << endl;
return 0;
} | [
"call.add",
"call.arguments.change"
] | 987,205 | 987,206 | u842028864 | cpp |
p03182 | #include <bits/stdc++.h>
#define int long long
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define file(s) \
freopen(s ".in", "r", stdin); \
freopen(s ".out", "w", stdout);
#define forev(i, b, a) for (int i = (b); i >= (a); --i)
#define forn(i, a, b) for (int i = (a); i <= (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
using namespace std;
typedef pair<long long, long long> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef vector<pii> vpii;
typedef vector<int> vi;
typedef long double ldb;
typedef long long ll;
typedef double db;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}, block = 555;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const int inf = 1e9, N = 2e5 + 48, mod = 1e9 + 7;
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;
int n, m, l, r, x, t[N << 2], add[N << 2], dp[N];
vpii gg[N];
vi g[N];
void push(int v) {
if (add[v]) {
add[v << 1] += add[v];
add[v << 1 | 1] += add[v];
t[v << 1] += add[v];
t[v << 1 | 1] += add[v];
add[v] = 0;
}
}
void update(int l, int r, int x, int v = 1, int tl = 0, int tr = n) {
if (l > r || l > tr || tl > r)
return;
if (l <= tl && tr <= r) {
t[v] += x;
add[v] += x;
return;
}
push(v);
int tm = (tl + tr) >> 1;
update(l, r, x, v << 1, tl, tm);
update(l, r, x, v << 1 | 1, tm + 1, tr);
t[v] = max(t[v << 1], t[v << 1 | 1]);
}
int get(int l, int r, int v = 1, int tl = 0, int tr = n) {
if (l > r || tl > r || l > tr)
return -INF;
if (l <= tl && tr <= r)
return t[v];
push(v);
int tm = (tl + tr) >> 1;
return max(get(l, r, v << 1, tl, tm), get(l, r, v << 1 | 1, tm + 1, tr));
}
main() {
cin >> n >> m;
while (m--) {
cin >> l >> r >> x;
g[l].pb(x);
gg[r + 1].pb({l, x});
}
forn(i, 1, n) {
for (auto x : g[i])
update(0, i - 1, x);
for (auto x : gg[i])
update(0, x.f - 1, -x.s);
dp[i] = get(0, i - 1);
update(i, i, dp[i]);
}
cout << *max_element(dp + 1, dp + 1 + n);
}
| #include <bits/stdc++.h>
#define int long long
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define file(s) \
freopen(s ".in", "r", stdin); \
freopen(s ".out", "w", stdout);
#define forev(i, b, a) for (int i = (b); i >= (a); --i)
#define forn(i, a, b) for (int i = (a); i <= (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
using namespace std;
typedef pair<long long, long long> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef vector<pii> vpii;
typedef vector<int> vi;
typedef long double ldb;
typedef long long ll;
typedef double db;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}, block = 555;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const int inf = 1e9, N = 2e5 + 48, mod = 1e9 + 7;
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;
int n, m, l, r, x, t[N << 2], add[N << 2], dp[N];
vpii gg[N];
vi g[N];
void push(int v) {
if (add[v]) {
add[v << 1] += add[v];
add[v << 1 | 1] += add[v];
t[v << 1] += add[v];
t[v << 1 | 1] += add[v];
add[v] = 0;
}
}
void update(int l, int r, int x, int v = 1, int tl = 0, int tr = n) {
if (l > r || l > tr || tl > r)
return;
if (l <= tl && tr <= r) {
t[v] += x;
add[v] += x;
return;
}
push(v);
int tm = (tl + tr) >> 1;
update(l, r, x, v << 1, tl, tm);
update(l, r, x, v << 1 | 1, tm + 1, tr);
t[v] = max(t[v << 1], t[v << 1 | 1]);
}
int get(int l, int r, int v = 1, int tl = 0, int tr = n) {
if (l > r || tl > r || l > tr)
return -INF;
if (l <= tl && tr <= r)
return t[v];
push(v);
int tm = (tl + tr) >> 1;
return max(get(l, r, v << 1, tl, tm), get(l, r, v << 1 | 1, tm + 1, tr));
}
main() {
cin >> n >> m;
while (m--) {
cin >> l >> r >> x;
g[l].pb(x);
gg[r + 1].pb({l, x});
}
forn(i, 1, n) {
for (auto x : g[i])
update(0, i - 1, x);
for (auto x : gg[i])
update(0, x.f - 1, -x.s);
dp[i] = get(0, i - 1);
update(i, i, dp[i]);
}
cout << *max_element(dp, dp + 1 + n);
}
| [
"expression.operation.binary.remove"
] | 987,209 | 987,210 | u089230684 | cpp |
p03183 | #include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_set>
#include <vector>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*
cout<<fixed<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod = 1000000007;
const llint big = 2.19e15 + 1;
const long double pai = 3.141592653589793238462643383279502884197;
const long double eps = 1e-15;
template <class T, class U> bool mineq(T &a, U b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T, class U> bool maxeq(T &a, U b) {
if (a < b) {
a = b;
return true;
}
return false;
}
llint gcd(llint a, llint b) {
if (a % b == 0) {
return b;
} else
return gcd(b, a % b);
}
llint lcm(llint a, llint b) {
if (a == 0) {
return b;
}
return a / gcd(a, b) * b;
}
template <class T> void SO(T &ve) { sort(ve.begin(), ve.end()); }
template <class T> void REV(T &ve) { reverse(ve.begin(), ve.end()); }
template <class T> llint LBI(vector<T> &ar, T in) {
return lower_bound(ar.begin(), ar.end(), in) - ar.begin();
}
template <class T> llint UBI(vector<T> &ar, T in) {
return upper_bound(ar.begin(), ar.end(), in) - ar.begin();
}
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
int i, n;
cin >> n;
vector<tuple<int, int, int>> blo(n);
for (i = 0; i < n; i++) {
int w, s, v;
cin >> w >> s >> v;
blo[i] = mt(w + s, w, v);
}
SO(blo);
static llint dp[10001] = {0};
for (auto it : blo) {
int s, w, v;
tie(s, w, v) = it;
for (i = s; i >= w; i--) {
maxeq(dp[i], dp[i - w] + v);
}
}
llint ans = 0;
for (i = 0; i <= 10000; i++) {
maxeq(ans, dp[i]);
}
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_set>
#include <vector>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*
cout<<fixed<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod = 1000000007;
const llint big = 2.19e15 + 1;
const long double pai = 3.141592653589793238462643383279502884197;
const long double eps = 1e-15;
template <class T, class U> bool mineq(T &a, U b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T, class U> bool maxeq(T &a, U b) {
if (a < b) {
a = b;
return true;
}
return false;
}
llint gcd(llint a, llint b) {
if (a % b == 0) {
return b;
} else
return gcd(b, a % b);
}
llint lcm(llint a, llint b) {
if (a == 0) {
return b;
}
return a / gcd(a, b) * b;
}
template <class T> void SO(T &ve) { sort(ve.begin(), ve.end()); }
template <class T> void REV(T &ve) { reverse(ve.begin(), ve.end()); }
template <class T> llint LBI(vector<T> &ar, T in) {
return lower_bound(ar.begin(), ar.end(), in) - ar.begin();
}
template <class T> llint UBI(vector<T> &ar, T in) {
return upper_bound(ar.begin(), ar.end(), in) - ar.begin();
}
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
int i, n;
cin >> n;
vector<tuple<int, int, int>> blo(n);
for (i = 0; i < n; i++) {
int w, s, v;
cin >> w >> s >> v;
blo[i] = mt(w + s, w, v);
}
SO(blo);
static llint dp[20001] = {0};
for (auto it : blo) {
int s, w, v;
tie(s, w, v) = it;
for (i = s; i >= w; i--) {
maxeq(dp[i], dp[i - w] + v);
}
}
llint ans = 0;
for (i = 0; i <= 20000; i++) {
maxeq(ans, dp[i]);
}
cout << ans << endl;
return 0;
}
| [
"literal.number.change",
"variable_declaration.array_dimensions.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 987,234 | 987,235 | u483814783 | cpp |
p03184 | #include <bits/stdc++.h>
#define ll long long int
#define lld long double
#define pb push_back
#define pii pair<ll, ll>
#define mi map<ll, ll>
#define vec vector<ll>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define mod 1000000007
#define nmod -1000000007
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define repi(i, a, b) for (ll i = a; i <= b; i++)
#define per(i, a, b) for (ll i = a; i >= b; i--)
#define mp make_pair
#define mit map<ll, ll>::iterator
#define sit set<ll>::iterator
#define pit pair<ll, ll>::iterator
#define xxx exit(0);
#define tr(container, it) \
for (__typeof(container.begin()) it = container.begin(); \
it != container.end(); it++)
using namespace std;
ll xo(ll x, ll y) { return (x | y) & (~x | ~y); }
ll bin_Expo(ll x, ll n) {
if (x == 0)
return 0;
if (n == 0)
return 1;
else if (n % 2 == 0) // n is even
return bin_Expo(x * x, n / 2);
else // n is odd
return x * bin_Expo(x * x, (n - 1) / 2);
}
ll mod_Expo(ll x, ll n, ll M) {
if (x == 0)
return 0;
if (n == 0)
return 1;
else if (n % 2 == 0) // n is even
return mod_Expo((x * x) % M, n / 2, M);
else // n is odd
return (x * mod_Expo((x * x) % M, (n - 1) / 2, M)) % M;
}
bool prime_check(ll x) {
bool prime = (x >= 2);
for (ll i = 2; i * i <= x; i++) {
if (x % i == 0) {
prime = false;
break;
}
}
return prime;
}
ll logg(ll base, ll x) { return (ll)(log(x) / log(base)); }
ll h, w, n, dp[100005], f[200005], fc[200005];
ll ways(ll x, ll y) {
if (x < 0 || y < 0)
return 0;
return (((f[x + y] * fc[x]) % mod) * fc[y]) % mod;
}
bool cc(pii &a, pii &b) { return (a.F + a.S) < (b.F + b.S); }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int TESTS = 1;
// cin>>TESTS;
while (TESTS--) {
ll i, l, j, x1, y1, x, y, q, h;
cin >> h >> w >> n;
vector<pii> z(n + 1);
rep(i, 0, n) {
cin >> x1 >> y1;
z[i] = {x1, y1};
}
z[n] = {mod, mod};
sort(all(z), cc);
z[n] = {h, w};
f[0] = 1;
fc[0] = 1;
dp[0] = 0;
repi(i, 1, 200004) {
f[i] = (f[i - 1] * i) % mod;
fc[i] = mod_Expo(f[i], mod - 2, mod);
dp[i] = 0;
}
repi(i, 0, n) {
dp[i] = ways(z[i].F - 1, z[i].S - 1);
rep(j, 0, i) {
if (z[i].F >= z[j].F && z[i].S >= z[j].S)
dp[i] =
(dp[i] -
((ways(z[i].F - z[j].F, z[i].S - z[j].S) * dp[j]) % mod) + mod) %
mod;
}
}
cout << dp[n];
}
return 0;
} | #include <bits/stdc++.h>
#define ll long long int
#define lld long double
#define pb push_back
#define pii pair<ll, ll>
#define mi map<ll, ll>
#define vec vector<ll>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define mod 1000000007
#define nmod -1000000007
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define repi(i, a, b) for (ll i = a; i <= b; i++)
#define per(i, a, b) for (ll i = a; i >= b; i--)
#define mp make_pair
#define mit map<ll, ll>::iterator
#define sit set<ll>::iterator
#define pit pair<ll, ll>::iterator
#define xxx exit(0);
#define tr(container, it) \
for (__typeof(container.begin()) it = container.begin(); \
it != container.end(); it++)
using namespace std;
ll xo(ll x, ll y) { return (x | y) & (~x | ~y); }
ll bin_Expo(ll x, ll n) {
if (x == 0)
return 0;
if (n == 0)
return 1;
else if (n % 2 == 0) // n is even
return bin_Expo(x * x, n / 2);
else // n is odd
return x * bin_Expo(x * x, (n - 1) / 2);
}
ll mod_Expo(ll x, ll n, ll M) {
if (x == 0)
return 0;
if (n == 0)
return 1;
else if (n % 2 == 0) // n is even
return mod_Expo((x * x) % M, n / 2, M);
else // n is odd
return (x * mod_Expo((x * x) % M, (n - 1) / 2, M)) % M;
}
bool prime_check(ll x) {
bool prime = (x >= 2);
for (ll i = 2; i * i <= x; i++) {
if (x % i == 0) {
prime = false;
break;
}
}
return prime;
}
ll logg(ll base, ll x) { return (ll)(log(x) / log(base)); }
ll h, w, n, dp[200005], f[200005], fc[200005];
ll ways(ll x, ll y) {
if (x < 0 || y < 0)
return 0;
return (((f[x + y] * fc[x]) % mod) * fc[y]) % mod;
}
bool cc(pii &a, pii &b) { return (a.F + a.S) < (b.F + b.S); }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int TESTS = 1;
// cin>>TESTS;
while (TESTS--) {
ll i, l, j, x1, y1, x, y, q, h;
cin >> h >> w >> n;
vector<pii> z(n + 1);
rep(i, 0, n) {
cin >> x1 >> y1;
z[i] = {x1, y1};
}
z[n] = {mod, mod};
sort(all(z), cc);
z[n] = {h, w};
f[0] = 1;
fc[0] = 1;
dp[0] = 0;
repi(i, 1, 200004) {
f[i] = (f[i - 1] * i) % mod;
fc[i] = mod_Expo(f[i], mod - 2, mod);
dp[i] = 0;
}
repi(i, 0, n) {
dp[i] = ways(z[i].F - 1, z[i].S - 1);
rep(j, 0, i) {
if (z[i].F >= z[j].F && z[i].S >= z[j].S)
dp[i] =
(dp[i] -
((ways(z[i].F - z[j].F, z[i].S - z[j].S) * dp[j]) % mod) + mod) %
mod;
}
}
cout << dp[n];
}
return 0;
} | [
"literal.number.change",
"variable_declaration.array_dimensions.change"
] | 987,248 | 987,249 | u334773822 | cpp |
p03184 |
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; ++i)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e18;
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % mod + mod) % mod) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
mint &operator-=(const mint a) {
if ((x += mod - a.x) >= mod)
x -= mod;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const { return mint(*this) += a; }
mint operator-(const mint a) const { return mint(*this) -= a; }
mint operator*(const mint a) const { return mint(*this) *= a; }
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod - 2); }
mint &operator/=(const mint a) { return *this *= a.inv(); }
mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
vector<mint> fact, ifact;
combination(int n) : fact(n + 1), ifact(n + 1) {
assert(n < mod);
fact[0] = 1;
for (int i = 1; i <= n; ++i)
fact[i] = fact[i - 1] * i;
ifact[n] = fact[n].inv();
for (int i = n; i >= 1; --i)
ifact[i - 1] = ifact[i] * i;
}
mint operator()(int n, int k) {
if (k < 0 || k > n)
return 0;
return fact[n] * ifact[k] * ifact[n - k];
}
} comb(100005);
// nPk
mint f(int n, int k) {
if (n < 0)
return 0;
// nPk = nCk * k!
mint res = comb(n, k);
res *= comb.fact[k];
return res;
}
//組み合わせの数nCrを計算
int calcNumOfCombination(int n, int r) {
int num = 1;
for (int i = 1; i <= r; i++) {
num = num * (n - i + 1) / i;
}
return num;
}
int main() {
ll h, w, n;
cin >> h >> w >> n;
vector<P> g(n);
rep(i, n) {
ll r1, c1;
cin >> r1 >> c1;
r1--;
c1--;
g[i] = make_pair(r1, c1);
}
sort(g.begin(), g.end());
mint dp[n + 5];
// mint test=comb(6,2);
// cout<<test;
rep(i, n) {
// cout<<"i"<<i<<endl;
ll r1 = g[i].first;
ll c1 = g[i].second;
// cout<<"r"<<r1<<"c"<<c1<<endl;
mint now = comb(r1 + c1, r1);
// cout<<now<<endl;
rep(j, n) {
ll r2 = g[j].first;
ll c2 = g[j].second;
if (r2 > r1 or c2 > c1)
continue;
mint temp = dp[j] * comb((r1 - r2 + c1 - c2), r1 - r2);
now -= temp;
}
// cout<<now<<endl;
dp[i] = now;
}
mint ans = comb(h + w - 2, w - 1);
// cout<<ans<<endl;
rep(i, n) {
ll hnow = h - 1 - g[i].first;
ll cnow = w - 1 - g[i].second;
mint temp = comb(hnow + cnow, hnow);
temp *= dp[i];
ans -= temp;
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; ++i)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e18;
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % mod + mod) % mod) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
mint &operator-=(const mint a) {
if ((x += mod - a.x) >= mod)
x -= mod;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const { return mint(*this) += a; }
mint operator-(const mint a) const { return mint(*this) -= a; }
mint operator*(const mint a) const { return mint(*this) *= a; }
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod - 2); }
mint &operator/=(const mint a) { return *this *= a.inv(); }
mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
vector<mint> fact, ifact;
combination(int n) : fact(n + 1), ifact(n + 1) {
assert(n < mod);
fact[0] = 1;
for (int i = 1; i <= n; ++i)
fact[i] = fact[i - 1] * i;
ifact[n] = fact[n].inv();
for (int i = n; i >= 1; --i)
ifact[i - 1] = ifact[i] * i;
}
mint operator()(int n, int k) {
if (k < 0 || k > n)
return 0;
return fact[n] * ifact[k] * ifact[n - k];
}
} comb(200005);
// nPk
mint f(int n, int k) {
if (n < 0)
return 0;
// nPk = nCk * k!
mint res = comb(n, k);
res *= comb.fact[k];
return res;
}
//組み合わせの数nCrを計算
int calcNumOfCombination(int n, int r) {
int num = 1;
for (int i = 1; i <= r; i++) {
num = num * (n - i + 1) / i;
}
return num;
}
int main() {
ll h, w, n;
cin >> h >> w >> n;
vector<P> g(n);
rep(i, n) {
ll r1, c1;
cin >> r1 >> c1;
r1--;
c1--;
g[i] = make_pair(r1, c1);
}
sort(g.begin(), g.end());
mint dp[n + 5];
// mint test=comb(6,2);
// cout<<test;
rep(i, n) {
// cout<<"i"<<i<<endl;
ll r1 = g[i].first;
ll c1 = g[i].second;
// cout<<"r"<<r1<<"c"<<c1<<endl;
mint now = comb(r1 + c1, r1);
// cout<<now<<endl;
rep(j, n) {
ll r2 = g[j].first;
ll c2 = g[j].second;
if (r2 > r1 or c2 > c1)
continue;
mint temp = dp[j] * comb((r1 - r2 + c1 - c2), r1 - r2);
now -= temp;
}
// cout<<now<<endl;
dp[i] = now;
}
mint ans = comb(h + w - 2, w - 1);
// cout<<ans<<endl;
rep(i, n) {
ll hnow = h - 1 - g[i].first;
ll cnow = w - 1 - g[i].second;
mint temp = comb(hnow + cnow, hnow);
temp *= dp[i];
ans -= temp;
}
cout << ans << endl;
}
| [
"literal.number.change",
"call.arguments.change"
] | 987,252 | 987,253 | u289381123 | cpp |
p03184 | #include <algorithm>
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <vector>
#define fast ios_base::sync_with_stdio(false)
#define mxn (ll)3e5
#define mod (ll)(1e9 + 7)
#define mod1 (ll)(998244353)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi>
#define pi pair<ll, ll>
#define vvpi vector<vector<pi>>
#define vpi vector<pi>
#define vppi vector<pair<ll, pi>>
#define vs vector<string>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
#define crz(v, n) v.clear(), v.resize(n + 1, 0)
#define print(v) \
for (ll it = 0; it < v.size(); it++) \
cout << v[it] << " "; \
cout << endl
#define printp(v) \
for (ll it = 0; it < v.size(); it++) \
cout << v[it].first << " " << v[it].second << endl
using namespace std;
vi f(mxn, 1);
struct node {
int x, y;
void read() { cin >> x >> y; }
bool operator<(const node &a) const {
if (a.x - x)
return x < a.x;
return y < a.y;
}
};
ll powe(ll x, ll y = mod - 2) {
x %= mod;
ll s = 1;
while (y) {
if (y % 2)
s = (s * x) % mod;
y /= 2;
x = (x * x) % mod;
}
return s;
}
ll ncr(int x, int y) {
if (x < 0 || y < 0)
return 0;
int n = x + y - 2, r = y - 1;
ll inv = (powe(f[n - r]) * powe(f[r])) % mod;
return (f[n] * inv) % mod;
}
int main() {
int h, w, i, n, j;
cin >> h >> w >> n;
vector<node> v(n + 1);
vi d(n + 2, 0);
for (i = 1; i < f.size(); i++)
f[i] = (f[i - 1] * i) % mod;
for (i = 1; i <= n; i++)
v[i].read();
sort(all(v));
v.eb(node{h, w});
// for(i=1;i<=n+1;i++) cout<<v[i].x<<" "<<v[i].y<<endl;
for (i = 1; i <= n + 1; i++) {
d[i] = ncr(v[i].x, v[i].y);
for (j = i - 1; j; j--) {
d[i] =
(d[i] - d[j] * ncr(v[i].x - v[j].x + 1, v[i].y - v[j].y + 1) % mod +
mod) %
mod;
}
}
cout << d[n + 1] << endl;
}
| #include <algorithm>
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <vector>
#define fast ios_base::sync_with_stdio(false)
#define mxn (ll)3e5
#define mod (ll)(1e9 + 7)
#define mod1 (ll)(998244353)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi>
#define pi pair<ll, ll>
#define vvpi vector<vector<pi>>
#define vpi vector<pi>
#define vppi vector<pair<ll, pi>>
#define vs vector<string>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
#define crz(v, n) v.clear(), v.resize(n + 1, 0)
#define print(v) \
for (ll it = 0; it < v.size(); it++) \
cout << v[it] << " "; \
cout << endl
#define printp(v) \
for (ll it = 0; it < v.size(); it++) \
cout << v[it].first << " " << v[it].second << endl
using namespace std;
vi f(mxn, 1);
struct node {
int x, y;
void read() { cin >> x >> y; }
bool operator<(const node &a) const {
if (a.x - x)
return x < a.x;
return y < a.y;
}
};
ll powe(ll x, ll y = mod - 2) {
x %= mod;
ll s = 1;
while (y) {
if (y % 2)
s = (s * x) % mod;
y /= 2;
x = (x * x) % mod;
}
return s;
}
ll ncr(int x, int y) {
if (x < 1 || y < 1)
return 0;
int n = x + y - 2, r = y - 1;
ll inv = (powe(f[n - r]) * powe(f[r])) % mod;
return (f[n] * inv) % mod;
}
int main() {
int h, w, i, n, j;
cin >> h >> w >> n;
vector<node> v(n + 1);
vi d(n + 2, 0);
for (i = 1; i < f.size(); i++)
f[i] = (f[i - 1] * i) % mod;
for (i = 1; i <= n; i++)
v[i].read();
sort(all(v));
v.eb(node{h, w});
for (i = 1; i <= n + 1; i++) {
d[i] = ncr(v[i].x, v[i].y);
for (j = i - 1; j; j--) {
d[i] =
(d[i] - d[j] * ncr(v[i].x - v[j].x + 1, v[i].y - v[j].y + 1) % mod +
mod) %
mod;
}
}
cout << d[n + 1] << endl;
}
| [
"literal.number.change",
"control_flow.branch.if.condition.change"
] | 987,256 | 987,257 | u163525690 | cpp |
p03184 | #include <bits/stdc++.h>
using namespace std;
#define LL long long int
#define MOD 1000000007
#define MAXN 2000000
LL fact[MAXN + 3];
LL fastExponentiation(LL base, int p) {
if (p == 0)
return 1;
LL half = fastExponentiation(base, p / 2);
LL halfhalf = (half * half) % MOD;
if (p % 2 == 0)
return halfhalf;
else
return (halfhalf * base) % MOD;
}
LL C(int n, int k) {
LL numerator = fact[n];
LL denominator = (fact[k] * fact[n - k]) % MOD;
return (numerator * fastExponentiation(denominator, MOD - 2)) % MOD;
}
// Solve the problem for given grid size nxm and blocks.
LL solve(int n, int m, vector<pair<int, int>> &blocks) {
fact[0] = 1;
for (int i = 1; i <= MAXN; i++)
fact[i] = (fact[i - 1] * i) % MOD;
blocks.push_back({n, m});
sort(blocks.begin(), blocks.end()); // sort in non-decreasing order of row and
// if tie by increasing order of column
int k = (int)blocks.size();
LL dp[k + 3]; // dp[i] = number of ways to go from (1, 1) to i-th block.
// Initially we pretend there are no blocks.
for (int i = 0; i < k; i++)
dp[i] = C(blocks[i].first + blocks[i].second - 2, blocks[i].first - 1);
// We add blocks one by one and update dp of affected blocks (ones on the
// right and down)
for (int i = 0; i < k; i++) {
for (int j = 0; j < k; j++) {
if (i == j)
continue;
if (blocks[j].first >= blocks[i].first &&
blocks[j].second >= blocks[i].second) {
int dr = blocks[j].first - blocks[i].first;
int dc = blocks[j].second - blocks[i].second;
// Number of ways to go to j decreased by number of ways to go to j that
// goes through i.
LL ij = (dp[i] * C(dr + dc, dr) % MOD) % MOD;
dp[j] = (dp[j] - ij + MOD) % MOD;
}
}
}
return dp[k - 1];
}
int main() {
int n, m, k;
cin >> n >> m >> k;
vector<pair<int, int>> blocks;
for (int i = 0; i < k; i++) {
int r, c;
cin >> r >> c;
blocks.push_back({r, c});
}
cout << solve(n, n, blocks) << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define LL long long int
#define MOD 1000000007
#define MAXN 2000000
LL fact[MAXN + 3];
LL fastExponentiation(LL base, int p) {
if (p == 0)
return 1;
LL half = fastExponentiation(base, p / 2);
LL halfhalf = (half * half) % MOD;
if (p % 2 == 0)
return halfhalf;
else
return (halfhalf * base) % MOD;
}
LL C(int n, int k) {
LL numerator = fact[n];
LL denominator = (fact[k] * fact[n - k]) % MOD;
return (numerator * fastExponentiation(denominator, MOD - 2)) % MOD;
}
// Solve the problem for given grid size nxm and blocks.
LL solve(int n, int m, vector<pair<int, int>> &blocks) {
fact[0] = 1;
for (int i = 1; i <= MAXN; i++)
fact[i] = (fact[i - 1] * i) % MOD;
blocks.push_back({n, m});
sort(blocks.begin(), blocks.end()); // sort in non-decreasing order of row and
// if tie by increasing order of column
int k = (int)blocks.size();
LL dp[k + 3]; // dp[i] = number of ways to go from (1, 1) to i-th block.
// Initially we pretend there are no blocks.
for (int i = 0; i < k; i++)
dp[i] = C(blocks[i].first + blocks[i].second - 2, blocks[i].first - 1);
// We add blocks one by one and update dp of affected blocks (ones on the
// right and down)
for (int i = 0; i < k; i++) {
for (int j = 0; j < k; j++) {
if (i == j)
continue;
if (blocks[j].first >= blocks[i].first &&
blocks[j].second >= blocks[i].second) {
int dr = blocks[j].first - blocks[i].first;
int dc = blocks[j].second - blocks[i].second;
// Number of ways to go to j decreased by number of ways to go to j that
// goes through i.
LL ij = (dp[i] * C(dr + dc, dr) % MOD) % MOD;
dp[j] = (dp[j] - ij + MOD) % MOD;
}
}
}
return dp[k - 1];
}
int main() {
int n, m, k;
cin >> n >> m >> k;
vector<pair<int, int>> blocks;
for (int i = 0; i < k; i++) {
int r, c;
cin >> r >> c;
blocks.push_back({r, c});
}
cout << solve(n, m, blocks) << endl;
}
| [
"identifier.change",
"io.output.change"
] | 987,258 | 987,259 | u569149712 | cpp |
p03184 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
#define ff first
#define ss second
#define pb push_back
#define all(s) (s).begin(), (s).end()
const ll mod = 1e9 + 7;
ll h, w, x;
vector<pair<ll, ll>> arr;
vi ans, fact;
ll binexp(ll a) {
ll res = 1, y = mod - 2;
while (y > 0) {
if (y & 1)
res = ((res * a) % mod + mod) % mod;
y >>= 1;
a = ((a * a) % mod + mod) % mod;
}
return res % mod;
}
ll num(ll x1, ll y1, ll x2, ll y2) {
ll x = fact[x2 - x1 + y2 - y1];
ll y = binexp(((fact[x2 - x1] * fact[y2 - y1]) % mod + mod) % mod);
return ((x * y) % mod + mod) % mod;
}
void solve() {
for (int i = 2; i <= h + w + 1; i++)
fact[i] = ((fact[i - 1] * i) % mod + mod) % mod;
for (int i = 0; i <= x; i++) {
ll ans_i = num(1, 1, arr[i].ff, arr[i].ss);
ll ans_t = 0;
for (int j = 0; j < i; j++) {
if (arr[j].ff <= arr[i].ff && arr[j].ss <= arr[i].ss) {
ans_t +=
(ans[j] * num(arr[j].ff, arr[j].ss, arr[i].ff, arr[i].ss) + mod) %
mod;
ans_t %= mod;
}
}
ans[i] = (ans_i - ans_t) % mod + mod;
ans[i] %= mod;
}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> h >> w >> x;
arr.resize(x);
ans.resize(x);
fact.resize(h + w + 1);
fact[0] = fact[1] = 1;
for (int i = 0; i < x; i++) {
ll a, b;
cin >> a >> b;
arr[i] = make_pair(a, b);
}
sort(all(arr));
arr.pb({h, w});
solve();
cout << ans[x] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
#define ff first
#define ss second
#define pb push_back
#define all(s) (s).begin(), (s).end()
const ll mod = 1e9 + 7;
ll h, w, x;
vector<pair<ll, ll>> arr;
vi ans, fact;
ll binexp(ll a) {
ll res = 1, y = mod - 2;
while (y > 0) {
if (y & 1)
res = ((res * a) % mod + mod) % mod;
y >>= 1;
a = ((a * a) % mod + mod) % mod;
}
return res % mod;
}
ll num(ll x1, ll y1, ll x2, ll y2) {
ll x = fact[x2 - x1 + y2 - y1];
ll y = binexp(((fact[x2 - x1] * fact[y2 - y1]) % mod + mod) % mod);
return ((x * y) % mod + mod) % mod;
}
void solve() {
for (int i = 2; i <= h + w; i++)
fact[i] = ((fact[i - 1] * i) % mod + mod) % mod;
for (int i = 0; i <= x; i++) {
ll ans_i = num(1, 1, arr[i].ff, arr[i].ss);
ll ans_t = 0;
for (int j = 0; j < i; j++) {
if (arr[j].ff <= arr[i].ff && arr[j].ss <= arr[i].ss) {
ans_t +=
(ans[j] * num(arr[j].ff, arr[j].ss, arr[i].ff, arr[i].ss) + mod) %
mod;
ans_t %= mod;
}
}
ans[i] = (ans_i - ans_t) % mod + mod;
ans[i] %= mod;
}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> h >> w >> x;
arr.resize(x);
ans.resize(x + 1);
fact.resize(h + w + 1);
fact[0] = fact[1] = 1;
for (int i = 0; i < x; i++) {
ll a, b;
cin >> a >> b;
arr[i] = make_pair(a, b);
}
sort(all(arr));
arr.pb({h, w});
solve();
cout << ans[x] << endl;
return 0;
} | [
"control_flow.loop.for.condition.change",
"expression.operation.binary.remove"
] | 987,266 | 987,265 | u828117122 | cpp |
p03184 | #include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>
const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;
using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
if (a.first == b.first)
return a.second < b.second;
return a.first < b.first;
}
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec) \
std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec) \
std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d) \
vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d) \
vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec) \
do { \
sort(ALL((vec))); \
(vec).erase(std::unique(ALL((vec))), (vec).end()); \
} while (0)
ll MODPOW(ll n, ll m) {
if (m == 0) {
return 1;
} else if (m % 2 == 0) {
ll tmp = MODPOW(n, m / 2);
return (tmp * tmp) % MOD;
} else {
return (n * MODPOW(n, m - 1)) % MOD;
}
}
ll MODDIV(ll a, ll b) { return a * MODPOW(b, MOD - 2) % MOD; }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll H, W, N;
cin >> H >> W >> N;
vl r(N + 2), c(N + 2);
r[0] = 1;
c[0] = 1;
REP(i, N) cin >> r[i + 1] >> c[i + 1];
r[N + 1] = H;
c[N + 1] = W;
ll start = 0;
ll goal = N + 1;
vvl reach(N + 2);
vl fact(H + W + 1, 0);
fact[0] = 1;
REP(i, H + W + 1) fact[i + 1] = ((i + 1) * fact[i]) % MOD;
REP(i, N + 2) REP(j, N + 2) {
if (i == j)
continue;
if (r[i] <= r[j] && c[i] <= c[j])
reach[i].push_back(j);
}
vector<pll> order;
REP(i, N + 2) order.emplace_back(r[i] + c[i], i);
sort(ALL(order));
vvl dp = VVL(N + 2, 2, 0);
dp[0][0] = 1;
REP(i, N + 2) {
ll u = order[i].second;
AUTO(v, reach[u]) {
ll rdif = r[v] - r[u];
ll cdif = c[v] - c[u];
ll mag = MODDIV(fact[rdif + cdif], (fact[rdif] * fact[cdif]) % MOD);
REP(p, 2) {
ll base = dp[u][p];
if (base == 0)
continue;
dp[v][1 - p] = (dp[v][1 - p] + (dp[u][p] * mag) % MOD) % MOD;
}
}
}
ll ans = (MOD + dp[goal][1] - dp[goal][0]) % MOD;
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>
const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;
using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
if (a.first == b.first)
return a.second < b.second;
return a.first < b.first;
}
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec) \
std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec) \
std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d) \
vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d) \
vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec) \
do { \
sort(ALL((vec))); \
(vec).erase(std::unique(ALL((vec))), (vec).end()); \
} while (0)
ll MODPOW(ll n, ll m) {
if (m == 0) {
return 1;
} else if (m % 2 == 0) {
ll tmp = MODPOW(n, m / 2);
return (tmp * tmp) % MOD;
} else {
return (n * MODPOW(n, m - 1)) % MOD;
}
}
ll MODDIV(ll a, ll b) { return a * MODPOW(b, MOD - 2) % MOD; }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll H, W, N;
cin >> H >> W >> N;
vl r(N + 2), c(N + 2);
r[0] = 1;
c[0] = 1;
REP(i, N) cin >> r[i + 1] >> c[i + 1];
r[N + 1] = H;
c[N + 1] = W;
ll start = 0;
ll goal = N + 1;
vvl reach(N + 2);
vl fact(H + W + 1, 0);
fact[0] = 1;
REP(i, H + W) fact[i + 1] = ((i + 1) * fact[i]) % MOD;
REP(i, N + 2) REP(j, N + 2) {
if (i == j)
continue;
if (r[i] <= r[j] && c[i] <= c[j])
reach[i].push_back(j);
}
vector<pll> order;
REP(i, N + 2) order.emplace_back(r[i] + c[i], i);
sort(ALL(order));
vvl dp = VVL(N + 2, 2, 0);
dp[0][0] = 1;
REP(i, N + 2) {
ll u = order[i].second;
AUTO(v, reach[u]) {
ll rdif = r[v] - r[u];
ll cdif = c[v] - c[u];
ll mag = MODDIV(fact[rdif + cdif], (fact[rdif] * fact[cdif]) % MOD);
REP(p, 2) {
ll base = dp[u][p];
if (base == 0)
continue;
dp[v][1 - p] = (dp[v][1 - p] + (dp[u][p] * mag) % MOD) % MOD;
}
}
}
ll ans = (MOD + dp[goal][1] - dp[goal][0]) % MOD;
cout << ans << endl;
return 0;
}
| [
"expression.operation.binary.remove"
] | 987,292 | 987,293 | u050865477 | cpp |
p03184 | #include <bits/stdc++.h>
using namespace std;
#define FAST \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define time_taken_start int begtime = clock();
#define time_taken_end \
int endtime = clock(); \
cerr << "\n\n" \
<< "Time elapsed: " << (endtime - begtime) * 1000 / CLOCKS_PER_SEC \
<< " ms\n\n"; \
return 0;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 1000000000000000007
#define eps 0.0000000001
#define pi acosl(-1)
#define pii pair<int, int>
#define pdd pair<ld, ld>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define vii vector<int>
#define vpl vector<pll>
#define vll vector<ll>
#define mseti multiset<ll>
#define msetd multiset<ll, greater<ll>>
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define stp fixed << setprecision(20)
#define endl '\n'
ll p[100009];
ll power(ll x, ll y) {
ll res = 1;
while (y > 0) {
if (y & 1)
res = res * x;
res %= mod;
y = y >> 1;
x = x * x;
x %= mod;
}
return res;
}
ll inv(ll x) { return power(x, mod - 2); }
ll ncr(ll n, ll r) {
ll res = p[n];
res *= inv(p[r]);
res %= mod;
res *= inv(p[n - r]);
res %= mod;
return res;
}
ll ans[3009];
int main() {
FAST
#ifdef ayk_16
time_taken_start freopen("input.txt", "rt", stdin);
freopen("output.txt", "wt", stdout);
#endif
p[0] = 1;
for (ll i = 1; i <= 100000; i++) {
p[i] = p[i - 1] * i;
p[i] %= mod;
}
ll h, w, n;
cin >> h >> w >> n;
vpl v;
v.pb({1, 1});
v.pb({h, w});
ll x, y;
for (ll i = 0; i < n; i++) {
cin >> x >> y;
v.pb({x, y});
}
sort(v.begin(), v.end());
for (ll i = 1; i <= n + 1; i++) {
ans[i] = ncr(v[i].ff + v[i].ss - 2, v[i].ss - 1);
}
for (ll i = 1; i <= n; i++) {
for (ll j = i + 1; j <= n + 1; j++) {
if (v[i].ss > v[j].ss)
continue;
ll d = v[j].ff - v[i].ff + v[j].ss - v[i].ss;
ll r = v[j].ss - v[i].ss;
x = ans[i] * ncr(d, r);
x %= mod;
ans[j] -= x;
ans[j] += mod;
ans[j] %= mod;
}
}
cout << ans[n + 1];
} | #include <bits/stdc++.h>
using namespace std;
#define FAST \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define time_taken_start int begtime = clock();
#define time_taken_end \
int endtime = clock(); \
cerr << "\n\n" \
<< "Time elapsed: " << (endtime - begtime) * 1000 / CLOCKS_PER_SEC \
<< " ms\n\n"; \
return 0;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 1000000000000000007
#define eps 0.0000000001
#define pi acosl(-1)
#define pii pair<int, int>
#define pdd pair<ld, ld>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define vii vector<int>
#define vpl vector<pll>
#define vll vector<ll>
#define mseti multiset<ll>
#define msetd multiset<ll, greater<ll>>
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define stp fixed << setprecision(20)
#define endl '\n'
ll p[200009];
ll power(ll x, ll y) {
ll res = 1;
while (y > 0) {
if (y & 1)
res = res * x;
res %= mod;
y = y >> 1;
x = x * x;
x %= mod;
}
return res;
}
ll inv(ll x) { return power(x, mod - 2); }
ll ncr(ll n, ll r) {
ll res = p[n];
res *= inv(p[r]);
res %= mod;
res *= inv(p[n - r]);
res %= mod;
return res;
}
ll ans[3009];
int main() {
FAST
#ifdef ayk_16
time_taken_start freopen("input.txt", "rt", stdin);
freopen("output.txt", "wt", stdout);
#endif
p[0] = 1;
for (ll i = 1; i <= 200000; i++) {
p[i] = p[i - 1] * i;
p[i] %= mod;
}
ll h, w, n;
cin >> h >> w >> n;
vpl v;
v.pb({1, 1});
v.pb({h, w});
ll x, y;
for (ll i = 0; i < n; i++) {
cin >> x >> y;
v.pb({x, y});
}
sort(v.begin(), v.end());
for (ll i = 1; i <= n + 1; i++) {
ans[i] = ncr(v[i].ff + v[i].ss - 2, v[i].ss - 1);
}
for (ll i = 1; i <= n; i++) {
for (ll j = i + 1; j <= n + 1; j++) {
if (v[i].ss > v[j].ss)
continue;
ll d = v[j].ff - v[i].ff + v[j].ss - v[i].ss;
ll r = v[j].ss - v[i].ss;
x = ans[i] * ncr(d, r);
x %= mod;
ans[j] -= x;
ans[j] += mod;
ans[j] %= mod;
}
}
cout << ans[n + 1];
} | [
"literal.number.change",
"variable_declaration.array_dimensions.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 987,305 | 987,306 | u002419600 | cpp |
p03184 | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
long long int H, W;
int N;
int r[3030], c[3030];
vector<pair<int, int>> V;
long long int dp[3030];
long long int MOD = 1000000007;
long long int P[200005], inv_P[200005];
long long int POW(long long int a, long long int k) {
if (k == 0) {
return 1;
} else if (k == 1) {
return a;
}
if (k % 2 == 1) {
return (POW(a, k - 1) * a) % MOD;
}
long long int ret = POW(a, k / 2);
return (ret * ret) % MOD;
}
long long int INV(long long int a) { return POW(a, MOD - 2); }
long long int C(long long int n, long long int m) {
long long int ret = P[n];
ret *= inv_P[m];
ret %= MOD;
ret *= inv_P[n - m];
ret %= MOD;
return ret;
}
int main(void) {
cin >> H >> W >> N;
for (int i = 1; i <= N; i++) {
cin >> r[i] >> c[i];
V.push_back(make_pair(r[i], c[i]));
}
V.push_back(make_pair(H, W));
sort(V.begin(), V.end());
//=====================
P[0] = 1;
P[1] = 1;
for (long long int i = 2; i <= 200000; i++) {
P[i] = (P[i - 1] * i) % MOD;
}
for (int i = 0; i <= 200000; i++) {
inv_P[i] = INV(P[i]);
}
//===============
for (int i = 0; i <= N; i++) {
int a = V[i].first;
int b = V[i].second;
long long int num = 0;
num = C(a - 1 + b - 1, a - 1); // cout << "num= " << num << endl;
for (int j = 0; j <= N; j++) {
int u = V[j].first;
int v = V[j].second;
if (u <= a && v <= b) {
long long int tmp = (C(a - u + b - v, a - u) * dp[j]) % MOD;
num -= tmp;
num %= MOD;
}
}
dp[i] = num;
}
cout << dp[N] << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
long long int H, W;
int N;
int r[3030], c[3030];
vector<pair<int, int>> V;
long long int dp[3030];
long long int MOD = 1000000007;
long long int P[200005], inv_P[200005];
long long int POW(long long int a, long long int k) {
if (k == 0) {
return 1;
} else if (k == 1) {
return a;
}
if (k % 2 == 1) {
return (POW(a, k - 1) * a) % MOD;
}
long long int ret = POW(a, k / 2);
return (ret * ret) % MOD;
}
long long int INV(long long int a) { return POW(a, MOD - 2); }
long long int C(long long int n, long long int m) {
long long int ret = P[n];
ret *= inv_P[m];
ret %= MOD;
ret *= inv_P[n - m];
ret %= MOD;
return ret;
}
int main(void) {
cin >> H >> W >> N;
for (int i = 1; i <= N; i++) {
cin >> r[i] >> c[i];
V.push_back(make_pair(r[i], c[i]));
}
V.push_back(make_pair(H, W));
sort(V.begin(), V.end());
//=====================
P[0] = 1;
P[1] = 1;
for (long long int i = 2; i <= 200000; i++) {
P[i] = (P[i - 1] * i) % MOD;
}
for (int i = 0; i <= 200000; i++) {
inv_P[i] = INV(P[i]);
}
//===============
for (int i = 0; i <= N; i++) {
int a = V[i].first;
int b = V[i].second;
long long int num = 0;
num = C(a - 1 + b - 1, a - 1); // cout << "num= " << num << endl;
for (int j = 0; j <= N; j++) {
int u = V[j].first;
int v = V[j].second;
if (u <= a && v <= b) {
long long int tmp = (C(a - u + b - v, a - u) * dp[j]) % MOD;
num = num - tmp + MOD;
num %= MOD;
}
}
dp[i] = num;
}
cout << dp[N] << endl;
return 0;
} | [
"assignment.value.change",
"assignment.change"
] | 987,311 | 987,312 | u835297884 | cpp |
p03184 | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; (i)--)
#define rrep1(i, n) for (int i = ((int)(n)); i > 0; (i)--)
#define sz(c) ((int)(c).size())
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> P;
typedef pair<int, pair<int, int>> PP;
const int MAX = 3e3 + 10;
const ll MOD = 1e9 + 7;
ll factm[200010];
void fact_init() {
int k = 2e5 + 5;
factm[0] = 1;
rep1(i, k) factm[i] = (factm[i - 1] * (ll)i) % MOD;
}
template <typename T> T extgcd(T a, T b, T &x, T &y) {
T d = a;
if (b != 0) {
d = extgcd(b, a % b, y, x);
y -= (a / b) * x;
} else {
x = 1;
y = 0;
}
return d;
}
template <typename T> T mod_inv(T a, T m) {
T x, y;
extgcd(a, m, x, y);
return (m + x % m) % m;
}
ll ifm[200010];
void ifm_init() {
rep1(i, 200005) { ifm[i] = mod_inv(factm[i], MOD); }
}
ll B(int r, int c) {
if (r < 0 || c < 0)
return 0;
ll tmp = (factm[r + c] * ifm[r]) % MOD;
tmp = (tmp * ifm[c]) % MOD;
return tmp;
}
int H, W, N;
vector<int> h, w;
vector<P> t;
void input() {
cin >> H >> W >> N;
H--;
W--;
t.pb(mp(0, 0));
rep(_, N) {
int r, c;
cin >> r >> c;
r--;
c--;
t.pb(mp(r, c));
}
t.pb(mp(H, W));
sort(all(t));
rep(i, N + 2) {
h.pb(t[i].fi);
w.pb(t[i].se);
}
fact_init();
ifm_init();
}
ll dp[MAX];
void solve() {
rep1(i, N + 1) {
dp[i] = B(h[i], w[i]);
rep1(j, i - 1) {
ll tmp = (dp[j] * B(h[i] - h[j], w[i] - w[j])) % MOD;
dp[i] = (dp[i] - tmp + MOD) % MOD;
}
}
}
void output() { cout << dp[N + 1]; }
int main() {
input();
solve();
output();
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; (i)--)
#define rrep1(i, n) for (int i = ((int)(n)); i > 0; (i)--)
#define sz(c) ((int)(c).size())
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> P;
typedef pair<int, pair<int, int>> PP;
const int MAX = 3e3 + 10;
const ll MOD = 1e9 + 7;
ll factm[200010];
void fact_init() {
int k = 2e5 + 5;
factm[0] = 1;
rep1(i, k) factm[i] = (factm[i - 1] * (ll)i) % MOD;
}
template <typename T> T extgcd(T a, T b, T &x, T &y) {
T d = a;
if (b != 0) {
d = extgcd(b, a % b, y, x);
y -= (a / b) * x;
} else {
x = 1;
y = 0;
}
return d;
}
template <typename T> T mod_inv(T a, T m) {
T x, y;
extgcd(a, m, x, y);
return (m + x % m) % m;
}
ll ifm[200010];
void ifm_init() {
rep(i, 200006) { ifm[i] = mod_inv(factm[i], MOD); }
}
ll B(int r, int c) {
if (r < 0 || c < 0)
return 0;
ll tmp = (factm[r + c] * ifm[r]) % MOD;
tmp = (tmp * ifm[c]) % MOD;
return tmp;
}
int H, W, N;
vector<int> h, w;
vector<P> t;
void input() {
cin >> H >> W >> N;
H--;
W--;
t.pb(mp(0, 0));
rep(_, N) {
int r, c;
cin >> r >> c;
r--;
c--;
t.pb(mp(r, c));
}
t.pb(mp(H, W));
sort(all(t));
rep(i, N + 2) {
h.pb(t[i].fi);
w.pb(t[i].se);
}
fact_init();
ifm_init();
}
ll dp[MAX];
void solve() {
rep1(i, N + 1) {
dp[i] = B(h[i], w[i]);
rep1(j, i - 1) {
ll tmp = (dp[j] * B(h[i] - h[j], w[i] - w[j])) % MOD;
dp[i] = (dp[i] - tmp + MOD) % MOD;
}
}
}
void output() { cout << dp[N + 1] << endl; }
int main() {
input();
solve();
output();
} | [
"identifier.change",
"call.function.change",
"literal.number.change",
"call.arguments.change",
"io.output.newline.add"
] | 987,315 | 987,316 | u228214259 | cpp |
p03184 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
// const ll mod = 998244353;
#define p_ary(ary, a, b, i) \
do { \
cout << "["; \
for (int(i) = (a); (i) < (b); ++(i)) \
cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); \
cout << "]\n"; \
} while (0)
#define p_map(map, it) \
do { \
cout << "{"; \
for (auto(it) = map.begin();; ++(it)) { \
if ((it) == map.end()) { \
cout << "}\n"; \
break; \
} else \
cout << "" << (it)->first << "=>" << (it)->second << ", "; \
} \
} while (0)
const int MAX_N = 200010;
ll fact[MAX_N], fact_inv[MAX_N], inv[MAX_N];
ll pow_mod(ll a, ll b) {
ll ret;
if (b < 0)
ret = pow_mod(a, mod + b - 1);
else if (b == 0)
ret = 1;
else if (b == 1)
ret = a;
else {
ll c = pow_mod(a, b / 2);
if (b % 2)
ret = (c * c) % mod * a % mod;
else
ret = c * c % mod;
}
return ret;
}
void create_table(int n) {
fact[0] = 1;
fact[1] = 1;
for (int i = 2; i <= n; ++i)
fact[i] = fact[i - 1] * i % mod;
fact_inv[n] = pow_mod(fact[n], mod - 2);
for (int i = n; i > 0; --i)
fact_inv[i - 1] = fact_inv[i] * i % mod;
for (int i = 1; i <= n; ++i)
inv[i] = fact_inv[i] * fact[i - 1] % mod;
}
ll combi(ll a, ll b) {
return fact[a] * fact_inv[b] % mod * fact_inv[a - b] % mod;
}
int main() {
int h, w, n;
cin >> h >> w >> n;
create_table(h + w);
vector<P> v(n);
vector<ll> dp(n, 0);
for (int i = 0; i < n; ++i)
cin >> v[i].first >> v[i].second;
sort(v.begin(), v.end());
v.push_back(P(h, w));
n++;
for (int i = 0; i < n; ++i) {
dp[i] = combi(v[i].first + v[i].second - 2, v[i].first - 1);
for (int j = 0; j < i; ++j)
if (v[j].first <= v[i].first && v[j].second <= v[i].second) {
dp[i] -=
dp[j] * combi(v[i].first - v[j].first + v[i].second - v[j].second,
v[i].first - v[j].first);
dp[i] %= mod;
}
}
cout << (dp[n - 1] + mod) % mod << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
// const ll mod = 998244353;
#define p_ary(ary, a, b, i) \
do { \
cout << "["; \
for (int(i) = (a); (i) < (b); ++(i)) \
cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); \
cout << "]\n"; \
} while (0)
#define p_map(map, it) \
do { \
cout << "{"; \
for (auto(it) = map.begin();; ++(it)) { \
if ((it) == map.end()) { \
cout << "}\n"; \
break; \
} else \
cout << "" << (it)->first << "=>" << (it)->second << ", "; \
} \
} while (0)
const int MAX_N = 200020;
ll fact[MAX_N], fact_inv[MAX_N], inv[MAX_N];
ll pow_mod(ll a, ll b) {
ll ret;
if (b < 0)
ret = pow_mod(a, mod + b - 1);
else if (b == 0)
ret = 1;
else if (b == 1)
ret = a;
else {
ll c = pow_mod(a, b / 2);
if (b % 2)
ret = (c * c) % mod * a % mod;
else
ret = c * c % mod;
}
return ret;
}
void create_table(int n) {
fact[0] = 1;
fact[1] = 1;
for (int i = 2; i <= n; ++i)
fact[i] = fact[i - 1] * i % mod;
fact_inv[n] = pow_mod(fact[n], mod - 2);
for (int i = n; i > 0; --i)
fact_inv[i - 1] = fact_inv[i] * i % mod;
for (int i = 1; i <= n; ++i)
inv[i] = fact_inv[i] * fact[i - 1] % mod;
}
ll combi(ll a, ll b) {
return fact[a] * fact_inv[b] % mod * fact_inv[a - b] % mod;
}
int main() {
int h, w, n;
cin >> h >> w >> n;
create_table(h + w + 10);
vector<P> v(n);
vector<ll> dp(n + 1, 0);
for (int i = 0; i < n; ++i)
cin >> v[i].first >> v[i].second;
sort(v.begin(), v.end());
v.push_back(P(h, w));
n++;
for (int i = 0; i < n; ++i) {
dp[i] = combi(v[i].first + v[i].second - 2, v[i].first - 1);
for (int j = 0; j < i; ++j)
if (v[j].first <= v[i].first && v[j].second <= v[i].second) {
dp[i] -=
dp[j] * combi(v[i].first - v[j].first + v[i].second - v[j].second,
v[i].first - v[j].first);
dp[i] %= mod;
}
}
cout << (dp[n - 1] + mod) % mod << endl;
return 0;
} | [
"literal.number.change",
"variable_declaration.value.change"
] | 987,319 | 987,320 | u506255180 | cpp |
p03184 | #include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define debug(x) cerr << #x << " = " << x << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
const int maxN = 1e5 + 5;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll sq(ll x) { return (x * x) % MOD; }
ll modP(ll a, ll b) {
return (!b ? 1 : (sq(modP(a, b / 2)) * (b % 2 ? a : 1)) % MOD);
}
ll fact[maxN], invfact[maxN];
void initFact() {
fact[0] = 1;
for (ll i = 1; i < maxN; i++) {
fact[i] = (fact[i - 1] * i) % MOD;
}
invfact[maxN - 1] = modP(fact[maxN - 1], MOD - 2);
for (ll i = maxN - 2; i > -1; i--) {
invfact[i] = (invfact[i + 1] * (i + 1)) % MOD;
}
}
ll choose(ll n, ll k) {
return (((fact[n] * invfact[k]) % MOD) * invfact[n - k]) % MOD;
}
ll dp[maxN];
pll P[maxN];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
initFact();
ll h, w, n;
cin >> h >> w >> n;
for (ll i = 0; i < n; i++) {
cin >> P[i].first >> P[i].second;
}
P[n] = {h, w};
sort(P, P + n + 1);
ll x = P[0].first;
ll y = P[0].second;
dp[0] = choose(x + y - 2, max(x - 1, y - 1));
for (ll i = 0; i <= n; i++) {
ll x = P[i].first;
ll y = P[i].second;
dp[i] = choose(x + y - 2, max(x - 1, y - 1));
for (ll j = 0; j < i; j++) {
if (P[i].second < P[j].second)
continue;
ll x = P[i].first - P[j].first;
ll y = P[i].second - P[j].second;
dp[i] -= dp[j] * choose(x + y, max(x, y));
dp[i] = (dp[i] + MOD) % MOD;
}
}
while (dp[n] < 0)
dp[n] += MOD;
cout << dp[n] % MOD << endl;
return 0;
}
| #include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define debug(x) cerr << #x << " = " << x << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
const int maxN = 2e5 + 5;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll sq(ll x) { return (x * x) % MOD; }
ll modP(ll a, ll b) {
return (!b ? 1 : (sq(modP(a, b / 2)) * (b % 2 ? a : 1)) % MOD);
}
ll fact[maxN], invfact[maxN];
void initFact() {
fact[0] = 1;
for (ll i = 1; i < maxN; i++) {
fact[i] = (fact[i - 1] * i) % MOD;
}
invfact[maxN - 1] = modP(fact[maxN - 1], MOD - 2);
for (ll i = maxN - 2; i > -1; i--) {
invfact[i] = (invfact[i + 1] * (i + 1)) % MOD;
}
}
ll choose(ll n, ll k) {
return (((fact[n] * invfact[k]) % MOD) * invfact[n - k]) % MOD;
}
ll dp[maxN];
pll P[maxN];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
initFact();
ll h, w, n;
cin >> h >> w >> n;
for (ll i = 0; i < n; i++) {
cin >> P[i].first >> P[i].second;
}
P[n] = {h, w};
sort(P, P + n + 1);
ll x = P[0].first;
ll y = P[0].second;
dp[0] = choose(x + y - 2, max(x - 1, y - 1));
for (ll i = 0; i <= n; i++) {
ll x = P[i].first;
ll y = P[i].second;
dp[i] = choose(x + y - 2, max(x - 1, y - 1));
for (ll j = 0; j < i; j++) {
if (P[i].second < P[j].second)
continue;
ll x = P[i].first - P[j].first;
ll y = P[i].second - P[j].second;
dp[i] -= dp[j] * choose(x + y, max(x, y));
dp[i] = (dp[i] + MOD) % MOD;
}
}
while (dp[n] < 0)
dp[n] += MOD;
cout << dp[n] % MOD << endl;
return 0;
}
| [
"literal.number.change",
"expression.operation.binary.change"
] | 987,323 | 987,324 | u032789819 | cpp |
p03184 | #include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int, int> ii;
vector<ii> adj;
const long long mod = 1000000007;
int fact[200000], invfact[200000], n, h, w, dp[200000], x, y;
int C(int k, int n) {
int ans = (invfact[k] % mod * invfact[n - k] % mod) % mod;
return (ans * fact[n]) % mod;
}
int binpow(int a, int n) {
if (n == 1)
return a;
int tmp = binpow(a, n / 2);
if (n % 2 == 0) {
return ((tmp % mod) * (tmp % mod)) % mod;
} else {
int ans = ((tmp % mod) * (a % mod)) % mod;
return (ans * (tmp % mod)) % mod;
}
}
signed main() {
cin >> h >> w >> n;
fact[0] = 1;
invfact[0] = 1;
for (int i = 1; i <= 3000; i++)
fact[i] = fact[i - 1] % mod * i % mod,
invfact[i] = binpow(fact[i], mod - 2) % mod;
for (int i = 0; i < n; i++) {
cin >> x >> y;
adj.push_back(ii(x, y));
}
sort(adj.begin(), adj.end());
adj.push_back(ii(h, w));
for (int i = 0; i <= n; i++) {
dp[i] = C(adj[i].first - 1, adj[i].first + adj[i].second - 2) % mod;
for (int j = 0; j < i; j++) {
if (adj[j].first <= adj[i].first && adj[j].second <= adj[i].second)
dp[i] = (dp[i] -
dp[j] % mod *
C(adj[i].first - adj[j].first,
adj[i].first - adj[j].first + adj[i].second -
adj[j].second) %
mod +
mod) %
mod;
}
}
cout << dp[n];
} | #include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int, int> ii;
vector<ii> adj;
const long long mod = 1000000007;
int fact[200500], invfact[200500], n, h, w, dp[200500], x, y;
int C(int k, int n) {
int ans = (invfact[k] % mod * invfact[n - k] % mod) % mod;
return (ans * fact[n]) % mod;
}
int binpow(int a, int n) {
if (n == 1)
return a;
int tmp = binpow(a, n / 2);
if (n % 2 == 0) {
return ((tmp % mod) * (tmp % mod)) % mod;
} else {
int ans = ((tmp % mod) * (a % mod)) % mod;
return (ans * (tmp % mod)) % mod;
}
}
signed main() {
cin >> h >> w >> n;
fact[0] = 1;
invfact[0] = 1;
for (int i = 1; i <= 200000; i++)
fact[i] = fact[i - 1] % mod * i % mod,
invfact[i] = binpow(fact[i], mod - 2) % mod;
for (int i = 0; i < n; i++) {
cin >> x >> y;
adj.push_back(ii(x, y));
}
sort(adj.begin(), adj.end());
adj.push_back(ii(h, w));
for (int i = 0; i <= n; i++) {
dp[i] = C(adj[i].first - 1, adj[i].first + adj[i].second - 2) % mod;
for (int j = 0; j < i; j++) {
if (adj[j].first <= adj[i].first && adj[j].second <= adj[i].second)
dp[i] = (dp[i] -
dp[j] % mod *
C(adj[i].first - adj[j].first,
adj[i].first - adj[j].first + adj[i].second -
adj[j].second) %
mod +
mod) %
mod;
}
}
cout << dp[n];
} | [
"literal.number.change",
"variable_declaration.array_dimensions.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 987,325 | 987,326 | u998997473 | cpp |
p03184 | #include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int, int> ii;
vector<ii> adj;
const long long mod = 1000000007;
int fact[3500], invfact[3500], n, h, w, dp[3500], x, y;
int C(int k, int n) {
int ans = (invfact[k] % mod * invfact[n - k] % mod) % mod;
return (ans * fact[n]) % mod;
}
int binpow(int a, int n) {
if (n == 1)
return a;
int tmp = binpow(a, n / 2);
if (n % 2 == 0) {
return ((tmp % mod) * (tmp % mod)) % mod;
} else {
int ans = ((tmp % mod) * (a % mod)) % mod;
return (ans * (tmp % mod)) % mod;
}
}
signed main() {
cin >> h >> w >> n;
fact[0] = 1;
invfact[0] = 1;
for (int i = 1; i <= 3000; i++)
fact[i] = fact[i - 1] % mod * i % mod,
invfact[i] = binpow(fact[i], mod - 2) % mod;
for (int i = 0; i < n; i++) {
cin >> x >> y;
adj.push_back(ii(x, y));
}
sort(adj.begin(), adj.end());
adj.push_back(ii(h, w));
for (int i = 0; i <= n; i++) {
dp[i] = C(adj[i].first - 1, adj[i].first + adj[i].second - 2) % mod;
for (int j = 0; j < i; j++) {
if (adj[j].first <= adj[i].first && adj[j].second <= adj[i].second)
dp[i] = (dp[i] -
dp[j] % mod *
C(adj[i].first - adj[j].first,
adj[i].first - adj[j].first + adj[i].second -
adj[j].second) %
mod +
mod) %
mod;
}
}
cout << dp[n];
} | #include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int, int> ii;
vector<ii> adj;
const long long mod = 1000000007;
int fact[200500], invfact[200500], n, h, w, dp[200500], x, y;
int C(int k, int n) {
int ans = (invfact[k] % mod * invfact[n - k] % mod) % mod;
return (ans * fact[n]) % mod;
}
int binpow(int a, int n) {
if (n == 1)
return a;
int tmp = binpow(a, n / 2);
if (n % 2 == 0) {
return ((tmp % mod) * (tmp % mod)) % mod;
} else {
int ans = ((tmp % mod) * (a % mod)) % mod;
return (ans * (tmp % mod)) % mod;
}
}
signed main() {
cin >> h >> w >> n;
fact[0] = 1;
invfact[0] = 1;
for (int i = 1; i <= 200000; i++)
fact[i] = fact[i - 1] % mod * i % mod,
invfact[i] = binpow(fact[i], mod - 2) % mod;
for (int i = 0; i < n; i++) {
cin >> x >> y;
adj.push_back(ii(x, y));
}
sort(adj.begin(), adj.end());
adj.push_back(ii(h, w));
for (int i = 0; i <= n; i++) {
dp[i] = C(adj[i].first - 1, adj[i].first + adj[i].second - 2) % mod;
for (int j = 0; j < i; j++) {
if (adj[j].first <= adj[i].first && adj[j].second <= adj[i].second)
dp[i] = (dp[i] -
dp[j] % mod *
C(adj[i].first - adj[j].first,
adj[i].first - adj[j].first + adj[i].second -
adj[j].second) %
mod +
mod) %
mod;
}
}
cout << dp[n];
} | [
"literal.number.change",
"variable_declaration.array_dimensions.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 987,327 | 987,326 | u998997473 | cpp |
p03184 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 3000;
const int MAXNUM = 3e5;
const ll MOD = 1e9 + 7;
struct Point {
int x, y;
};
int h, w, n;
Point arr[MAXN + 10];
ll fact[MAXNUM + 10], invfact[MAXNUM + 10];
ll mypow(ll x, ll y) {
if (y == 0)
return 1;
if (y % 2)
return mypow(x, y - 1) * x % MOD;
ll t = mypow(x, y / 2);
return t * t % MOD;
}
ll comb(int n, int r) {
if (n < r)
return 0;
return fact[n] * invfact[r] % MOD * invfact[n - r] % MOD;
}
ll dp[MAXN + 10];
int main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(false);
ll i, j;
fact[0] = 1;
for (i = 1; i <= MAXNUM; i++)
fact[i] = fact[i - 1] * i % MOD;
invfact[MAXNUM] = mypow(fact[MAXNUM], MOD - 2);
for (i = MAXNUM - 1; i >= 0; i--)
invfact[i] = invfact[i + 1] * (i + 1) % MOD;
scanf("%d%d%d", &h, &w, &n);
for (i = 0; i < n; i++)
scanf("%d%d", &arr[i].x, &arr[i].y);
sort(arr, arr + n, [](const Point &p, const Point &q) {
if (p.x == q.x)
return p.y < q.y;
else
return p.x < q.x;
});
arr[n] = {h, w};
for (i = 0; i <= n; i++) {
dp[i] = comb(arr[i].x + arr[i].y, arr[i].x);
for (j = 0; j < i; j++)
if (arr[j].x <= arr[i].x && arr[j].y <= arr[i].y)
dp[i] = (dp[i] -
dp[j] *
comb(arr[i].x - arr[j].x + arr[i].y - arr[j].y,
arr[i].x - arr[j].x) %
MOD +
MOD) %
MOD;
}
printf("%lld", dp[n]);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 3000;
const int MAXNUM = 3e5;
const ll MOD = 1e9 + 7;
struct Point {
int x, y;
};
int h, w, n;
Point arr[MAXN + 10];
ll fact[MAXNUM + 10], invfact[MAXNUM + 10];
ll mypow(ll x, ll y) {
if (y == 0)
return 1;
if (y % 2)
return mypow(x, y - 1) * x % MOD;
ll t = mypow(x, y / 2);
return t * t % MOD;
}
ll comb(int n, int r) {
if (n < r)
return 0;
return fact[n] * invfact[r] % MOD * invfact[n - r] % MOD;
}
ll dp[MAXN + 10];
int main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(false);
ll i, j;
fact[0] = 1;
for (i = 1; i <= MAXNUM; i++)
fact[i] = fact[i - 1] * i % MOD;
invfact[MAXNUM] = mypow(fact[MAXNUM], MOD - 2);
for (i = MAXNUM - 1; i >= 0; i--)
invfact[i] = invfact[i + 1] * (i + 1) % MOD;
scanf("%d%d%d", &h, &w, &n);
for (i = 0; i < n; i++)
scanf("%d%d", &arr[i].x, &arr[i].y);
sort(arr, arr + n, [](const Point &p, const Point &q) {
if (p.x == q.x)
return p.y < q.y;
else
return p.x < q.x;
});
arr[n] = {h, w};
for (i = 0; i <= n; i++) {
dp[i] = comb(arr[i].x + arr[i].y - 2, arr[i].x - 1);
for (j = 0; j < i; j++)
if (arr[j].x <= arr[i].x && arr[j].y <= arr[i].y)
dp[i] = (dp[i] -
dp[j] *
comb(arr[i].x - arr[j].x + arr[i].y - arr[j].y,
arr[i].x - arr[j].x) %
MOD +
MOD) %
MOD;
}
printf("%lld", dp[n]);
return 0;
} | [
"assignment.change"
] | 987,328 | 987,329 | u998997473 | cpp |
p03184 | #include <bits/stdc++.h>
using namespace std;
#define MAXN 100005
typedef long long ll;
const ll mod = 1e9 + 7;
ll fac[MAXN], ifac[MAXN];
ll fastpow(ll a, ll b) {
ll res = 1;
while (b) {
if (b & 1)
(res *= a) %= mod;
(a *= a) %= mod;
b >>= 1;
}
return res;
}
ll C(int m, int n) { return fac[m] * ifac[n] % mod * ifac[m - n] % mod; }
struct T {
int x, y;
} a[MAXN];
bool cmp(T a, T b) { return a.x < b.x || (a.x == b.x && a.y < b.y); }
ll ans[MAXN];
int main() {
fac[0] = ifac[0] = 1;
for (int i = 1; i < MAXN; i++)
fac[i] = fac[i - 1] * i % mod,
ifac[i] = ifac[i - 1] * fastpow(i, mod - 2) % mod;
int h, w, n;
cin >> h >> w >> n;
for (int i = 1; i <= n; i++)
scanf("%d%d", &a[i].x, &a[i].y);
sort(a + 1, a + n + 1, cmp);
++n;
a[n].x = h;
a[n].y = w;
for (int i = 1; i <= n; i++)
ans[i] = C(a[i].x + a[i].y - 2, a[i].x - 1);
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++)
if (a[i].x <= a[j].x && a[i].y <= a[j].y) {
ll x = a[j].x - a[i].x + 1, y = a[j].y - a[i].y + 1;
ans[j] = (ans[j] - C(x + y - 2, x - 1) * ans[i] % mod + mod) % mod;
}
cout << ans[n] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define MAXN 200005
typedef long long ll;
const ll mod = 1e9 + 7;
ll fac[MAXN], ifac[MAXN];
ll fastpow(ll a, ll b) {
ll res = 1;
while (b) {
if (b & 1)
(res *= a) %= mod;
(a *= a) %= mod;
b >>= 1;
}
return res;
}
ll C(int m, int n) { return fac[m] * ifac[n] % mod * ifac[m - n] % mod; }
struct T {
int x, y;
} a[MAXN];
bool cmp(T a, T b) { return a.x < b.x || (a.x == b.x && a.y < b.y); }
ll ans[MAXN];
int main() {
fac[0] = ifac[0] = 1;
for (int i = 1; i < MAXN; i++)
fac[i] = fac[i - 1] * i % mod,
ifac[i] = ifac[i - 1] * fastpow(i, mod - 2) % mod;
int h, w, n;
cin >> h >> w >> n;
for (int i = 1; i <= n; i++)
scanf("%d%d", &a[i].x, &a[i].y);
sort(a + 1, a + n + 1, cmp);
++n;
a[n].x = h;
a[n].y = w;
for (int i = 1; i <= n; i++)
ans[i] = C(a[i].x + a[i].y - 2, a[i].x - 1);
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++)
if (a[i].x <= a[j].x && a[i].y <= a[j].y) {
ll x = a[j].x - a[i].x + 1, y = a[j].y - a[i].y + 1;
ans[j] = (ans[j] - C(x + y - 2, x - 1) * ans[i] % mod + mod) % mod;
}
cout << ans[n] << endl;
return 0;
} | [
"preprocessor.define.value.change",
"literal.integer.change"
] | 987,330 | 987,331 | u978171121 | cpp |
p03184 | #include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using int64 = long long;
template <typename T = int> struct Range {
struct RangeIterator {
T i, step;
RangeIterator(T i, T step) : i{i}, step{step} {}
T &operator*() { return i; }
RangeIterator &operator++() {
i += step;
return *this;
}
bool operator!=(const RangeIterator &rhs) const {
return (step > 0 && i < rhs.i) || (step < 0 && i > rhs.i);
}
};
T start, stop, step;
Range(T start, T stop, T step) : start{start}, stop{stop}, step{step} {}
Range(T start, T stop) : Range(start, stop, 1) {}
Range(T stop) : Range(0, stop, 1) {}
RangeIterator begin() const { return RangeIterator(start, step); }
RangeIterator end() const { return RangeIterator(stop, step); }
};
using Square = std::pair<int, int>;
static constexpr int64 MOD = 1e9 + 7;
static int64 dp[3010], factorial[200005], inv_factorial[200005];
int64 powMod(int64 a, int64 n) {
int64 res = 1, p = a % MOD;
while (n > 0) {
if (n & 1)
(res *= p) %= MOD;
(p *= p) %= MOD;
n >>= 1;
}
return res;
}
void buildFactorialTable() {
factorial[0] = 1;
for (int n : Range<>(1, 200001)) {
factorial[n] = (n * factorial[n - 1]) % MOD;
}
inv_factorial[200000] = powMod(factorial[200000], MOD - 2);
for (int n : Range<>(200000, 0, -1)) {
inv_factorial[n - 1] = (n * inv_factorial[n]) % MOD;
}
}
int64 choose(int n, int k) {
if (n < 0 || k < 0)
return 0;
int64 res = factorial[n];
(res *= inv_factorial[k]) %= MOD;
(res *= inv_factorial[n - k]) %= MOD;
return res;
}
int64 countWays(Square start, Square goal) {
int dr = goal.first - start.first, dc = goal.second - start.second;
return choose(dr + dc, dr);
}
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
int h, w, n;
std::cin >> h >> w >> n;
std::vector<Square> squares(n);
for (int i : Range<>(n)) {
std::cin >> squares[i].first >> squares[i].second;
}
std::sort(squares.begin(), squares.end());
buildFactorialTable();
for (int i : Range<>(n)) {
dp[i] = countWays(Square(1, 1), squares[i]);
for (int j : Range<>(i)) {
if (squares[j] <= squares[i]) {
dp[i] -= (dp[j] * countWays(squares[j], squares[i])) % MOD;
dp[i] += MOD;
dp[i] %= MOD;
}
}
}
int64 ans = countWays(Square(1, 1), Square(h, w));
for (int i : Range<>(n)) {
ans -= (dp[i] * countWays(squares[i], Square(h, w))) % MOD;
ans += MOD;
ans %= MOD;
}
std::cout << ans << std::endl;
return 0;
}
| #include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using int64 = long long;
template <typename T = int> struct Range {
struct RangeIterator {
T i, step;
RangeIterator(T i, T step) : i{i}, step{step} {}
T &operator*() { return i; }
RangeIterator &operator++() {
i += step;
return *this;
}
bool operator!=(const RangeIterator &rhs) const {
return (step > 0 && i < rhs.i) || (step < 0 && i > rhs.i);
}
};
T start, stop, step;
Range(T start, T stop, T step) : start{start}, stop{stop}, step{step} {}
Range(T start, T stop) : Range(start, stop, 1) {}
Range(T stop) : Range(0, stop, 1) {}
RangeIterator begin() const { return RangeIterator(start, step); }
RangeIterator end() const { return RangeIterator(stop, step); }
};
using Square = std::pair<int, int>;
static constexpr int64 MOD = 1e9 + 7;
static int64 dp[3010], factorial[200005], inv_factorial[200005];
int64 powMod(int64 a, int64 n) {
int64 res = 1, p = a % MOD;
while (n > 0) {
if (n & 1)
(res *= p) %= MOD;
(p *= p) %= MOD;
n >>= 1;
}
return res;
}
void buildFactorialTable() {
factorial[0] = 1;
for (int n : Range<>(1, 200001)) {
factorial[n] = (n * factorial[n - 1]) % MOD;
}
inv_factorial[200000] = powMod(factorial[200000], MOD - 2);
for (int n : Range<>(200000, 0, -1)) {
inv_factorial[n - 1] = (n * inv_factorial[n]) % MOD;
}
}
int64 choose(int n, int k) {
if (n < k)
return 0;
int64 res = factorial[n];
(res *= inv_factorial[k]) %= MOD;
(res *= inv_factorial[n - k]) %= MOD;
return res;
}
int64 countWays(Square start, Square goal) {
int dr = goal.first - start.first, dc = goal.second - start.second;
return choose(dr + dc, dr);
}
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
int h, w, n;
std::cin >> h >> w >> n;
std::vector<Square> squares(n);
for (int i : Range<>(n)) {
std::cin >> squares[i].first >> squares[i].second;
}
std::sort(squares.begin(), squares.end());
buildFactorialTable();
for (int i : Range<>(n)) {
dp[i] = countWays(Square(1, 1), squares[i]);
for (int j : Range<>(i)) {
if (squares[j] <= squares[i]) {
dp[i] -= (dp[j] * countWays(squares[j], squares[i])) % MOD;
dp[i] += MOD;
dp[i] %= MOD;
}
}
}
int64 ans = countWays(Square(1, 1), Square(h, w));
for (int i : Range<>(n)) {
ans -= (dp[i] * countWays(squares[i], Square(h, w))) % MOD;
ans += MOD;
ans %= MOD;
}
std::cout << ans << std::endl;
return 0;
}
| [
"expression.operation.binary.remove"
] | 987,342 | 987,343 | u602850810 | cpp |
p03184 | /*
Author: @karngyan
Team: BlundersPride
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef std::vector<ll> vll;
typedef std::pair<ll, ll> pll;
typedef std::vector<vll> vvll;
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define endl '\n'
#define pb push_back
#define rep(i, a, b) for (ll i = a; i < b; ++i)
#define rrep(i, a, b) for (ll i = a; i > b; --i)
#define max3(a, b, c) max(a, max(b, c))
#define cres(c, n) (c).clear(), (c).resize(n)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define ff first
#define ss second
#define mk make_pair
const ll N = 1e5 + 10;
const ll m = 1e9 + 7;
ll fact[N], ifact[N];
ll pow(ll a, ll b) {
ll ans = 1;
while (b) {
if (b & 1)
ans = (ans * a) % m;
b /= 2;
a = (a * a) % m;
}
return ans;
}
ll modinv(ll k) { return pow(k, m - 2); }
void precompute() {
fact[0] = fact[1] = 1;
rep(i, 2, N) {
fact[i] = fact[i - 1] * i;
fact[i] %= m;
}
ifact[N - 1] = modinv(fact[N - 1]);
for (ll i = N - 2; i >= 0; --i) {
ifact[i] = ifact[i + 1] * (i + 1);
ifact[i] %= m;
}
}
ll ncr(ll n, ll r) {
if (r > n)
return 0;
return ((fact[n] * ifact[r]) % m * ifact[n - r]) % m;
}
ll h, w;
vector<pll> v;
ll ways(pll a, pll b) {
ll n = abs(a.ff - b.ff);
ll m = abs(a.ss - b.ss);
return ncr(n + m, n);
}
ll dp[3005];
signed main() {
fast;
////////////////////////////////////////////////////////////////////////////////////////////
precompute();
ll n;
cin >> h >> w >> n;
while (n--) {
ll i, j;
cin >> i >> j;
v.pb({i, j});
}
v.pb({h, w});
v.pb({1, 1});
sort(all(v));
n = v.size();
for (ll i = 1; i < n; ++i) {
dp[i] = ways(v[i], {1, 1});
for (ll j = 1; j < i; ++j) {
if (v[j].ff <= v[i].ff and v[j].ss <= v[i].ss) {
dp[i] = (dp[i] - dp[j] * ways(v[i], v[j]) + m) % m;
}
}
}
dp[n - 1] += m;
dp[n - 1] %= m;
cout << dp[n - 1] << endl;
return 0;
}
| /*
Author: @karngyan
Team: BlundersPride
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef std::vector<ll> vll;
typedef std::pair<ll, ll> pll;
typedef std::vector<vll> vvll;
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define endl '\n'
#define pb push_back
#define rep(i, a, b) for (ll i = a; i < b; ++i)
#define rrep(i, a, b) for (ll i = a; i > b; --i)
#define max3(a, b, c) max(a, max(b, c))
#define cres(c, n) (c).clear(), (c).resize(n)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define ff first
#define ss second
#define mk make_pair
const ll N = 2e5 + 10;
const ll m = 1e9 + 7;
ll fact[N], ifact[N];
ll pow(ll a, ll b) {
ll ans = 1;
while (b) {
if (b & 1)
ans = (ans * a) % m;
b /= 2;
a = (a * a) % m;
}
return ans;
}
ll modinv(ll k) { return pow(k, m - 2); }
void precompute() {
fact[0] = fact[1] = 1;
rep(i, 2, N) {
fact[i] = fact[i - 1] * i;
fact[i] %= m;
}
ifact[N - 1] = modinv(fact[N - 1]);
for (ll i = N - 2; i >= 0; --i) {
ifact[i] = ifact[i + 1] * (i + 1);
ifact[i] %= m;
}
}
ll ncr(ll n, ll r) {
if (r > n)
return 0;
return ((fact[n] * ifact[r]) % m * ifact[n - r]) % m;
}
ll h, w;
vector<pll> v;
ll ways(pll a, pll b) {
ll n = abs(a.ff - b.ff);
ll m = abs(a.ss - b.ss);
return ncr(n + m, n);
}
ll dp[3005];
signed main() {
fast;
////////////////////////////////////////////////////////////////////////////////////////////
precompute();
ll n;
cin >> h >> w >> n;
while (n--) {
ll i, j;
cin >> i >> j;
v.pb({i, j});
}
v.pb({h, w});
v.pb({1, 1});
sort(all(v));
n = v.size();
for (ll i = 1; i < n; ++i) {
dp[i] = ways(v[i], {1, 1});
for (ll j = 1; j < i; ++j) {
if (v[j].ff <= v[i].ff and v[j].ss <= v[i].ss) {
dp[i] = (dp[i] - dp[j] * ways(v[i], v[j]) + m) % m;
}
}
}
dp[n - 1] += m;
dp[n - 1] %= m;
cout << dp[n - 1] << endl;
return 0;
}
| [
"literal.number.change",
"expression.operation.binary.change"
] | 987,351 | 987,352 | u863090510 | cpp |
p03184 | /*
Author: @karngyan
Team: BlundersPride
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef std::vector<ll> vll;
typedef std::pair<ll, ll> pll;
typedef std::vector<vll> vvll;
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define endl '\n'
#define pb push_back
#define rep(i, a, b) for (ll i = a; i < b; ++i)
#define rrep(i, a, b) for (ll i = a; i > b; --i)
#define max3(a, b, c) max(a, max(b, c))
#define cres(c, n) (c).clear(), (c).resize(n)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define ff first
#define ss second
#define mk make_pair
const ll N = 1e5 + 10;
const ll m = 1e9 + 7;
ll fact[N], ifact[N];
ll pow(ll a, ll b) {
ll ans = 1;
while (b) {
if (b & 1)
ans = (ans * a) % m;
b /= 2;
a = (a * a) % m;
}
return ans;
}
ll modinv(ll k) { return pow(k, m - 2); }
void precompute() {
fact[0] = fact[1] = 1;
rep(i, 2, N) {
fact[i] = fact[i - 1] * i;
fact[i] %= m;
}
ifact[N - 1] = modinv(fact[N - 1]);
for (ll i = N - 2; i >= 0; --i) {
ifact[i] = ifact[i + 1] * (i + 1);
ifact[i] %= m;
}
}
ll ncr(ll n, ll r) {
if (r > n)
return 0;
return ((fact[n] * ifact[r]) % m * ifact[n - r]) % m;
}
ll h, w;
vector<pll> v;
ll ways(pll a, pll b) {
ll n = abs(a.ff - b.ff);
ll m = abs(a.ss - b.ss);
return ncr(n + m, n);
}
ll dp[3005];
signed main() {
fast;
////////////////////////////////////////////////////////////////////////////////////////////
precompute();
ll n;
cin >> h >> w >> n;
while (n--) {
ll i, j;
cin >> i >> j;
v.pb({i, j});
}
v.pb({h, w});
v.pb({1, 1});
sort(all(v));
n = v.size();
for (ll i = 1; i < n; ++i) {
dp[i] = ways(v[i], {1, 1});
for (ll j = 1; j < i; ++j) {
if (v[j].ff <= v[i].ff and v[j].ss <= v[i].ss) {
dp[i] = (dp[i] - dp[j] * ways(v[i], v[j]) + m) % m;
}
}
}
dp[n - 1] += m;
dp[n - 1] %= m;
cout << dp[n - 1] << endl;
return 0;
}
| /*
Author: @karngyan
Team: BlundersPride
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef std::vector<ll> vll;
typedef std::pair<ll, ll> pll;
typedef std::vector<vll> vvll;
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define endl '\n'
#define pb push_back
#define rep(i, a, b) for (ll i = a; i < b; ++i)
#define rrep(i, a, b) for (ll i = a; i > b; --i)
#define max3(a, b, c) max(a, max(b, c))
#define cres(c, n) (c).clear(), (c).resize(n)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define ff first
#define ss second
#define mk make_pair
const ll N = 1e6 + 10;
const ll m = 1e9 + 7;
ll fact[N], ifact[N];
ll pow(ll a, ll b) {
ll ans = 1;
while (b) {
if (b & 1)
ans = (ans * a) % m;
b /= 2;
a = (a * a) % m;
}
return ans;
}
ll modinv(ll k) { return pow(k, m - 2); }
void precompute() {
fact[0] = fact[1] = 1;
rep(i, 2, N) {
fact[i] = fact[i - 1] * i;
fact[i] %= m;
}
ifact[N - 1] = modinv(fact[N - 1]);
for (ll i = N - 2; i >= 0; --i) {
ifact[i] = ifact[i + 1] * (i + 1);
ifact[i] %= m;
}
}
ll ncr(ll n, ll r) {
if (r > n)
return 0;
return ((fact[n] * ifact[r]) % m * ifact[n - r]) % m;
}
ll h, w;
vector<pll> v;
ll ways(pll a, pll b) {
ll n = abs(a.ff - b.ff);
ll m = abs(a.ss - b.ss);
return ncr(n + m, n);
}
ll dp[3005];
signed main() {
fast;
////////////////////////////////////////////////////////////////////////////////////////////
precompute();
ll n;
cin >> h >> w >> n;
while (n--) {
ll i, j;
cin >> i >> j;
v.pb({i, j});
}
v.pb({h, w});
v.pb({1, 1});
sort(all(v));
n = v.size();
for (ll i = 1; i < n; ++i) {
dp[i] = ways(v[i], {1, 1});
for (ll j = 1; j < i; ++j) {
if (v[j].ff <= v[i].ff and v[j].ss <= v[i].ss) {
dp[i] = (dp[i] - dp[j] * ways(v[i], v[j]) + m) % m;
}
}
}
dp[n - 1] += m;
dp[n - 1] %= m;
cout << dp[n - 1] << endl;
return 0;
}
| [
"literal.number.change",
"expression.operation.binary.change"
] | 987,351 | 987,353 | u863090510 | cpp |
p03184 | #include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forlr(i, l, r) for (int i = int(l); i <= int(r); i++)
#define repeat(n) for (int hjfjke = 0; hjfjke < int(n); hjfjke++)
#define all(c) c.begin(), c.end()
#define ll long long
const int mod = 1000000007;
inline int add(int a, int b);
inline int mult(int a, int b);
inline int sub(int a, int b);
inline int divv(int a, int b);
struct block {
int w, s, v;
bool operator<(block &other) { return s + w < other.s + other.w; }
};
int p[100500];
int c(int n, int k) { return divv(divv(p[n], p[k]), p[n - k]); }
int dp[3050];
int32_t main() {
std::iostream::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout << fixed << setprecision(10);
p[0] = 1;
for (int i = 1; i < 100500; i++)
p[i] = mult(p[i - 1], i);
int h, w;
cin >> h >> w;
vector<pair<int, int>> v;
v.emplace_back(h, w);
int n;
cin >> n;
while (n--) {
int r, c;
cin >> r >> c;
v.emplace_back(r, c);
}
sort(v.begin(), v.end());
forn(i, v.size()) {
int res = c(v[i].first + v[i].second - 2, v[i].first - 1);
forn(j, i) if (v[j].first <= v[i].first && v[j].second <= v[i].second) res =
sub(res,
mult(dp[j], c(v[i].first - v[j].first + v[i].second - v[j].second,
v[i].second - v[j].second)));
dp[i] = res;
// cout << res << endl;
}
cout << dp[v.size() - 1];
return 0;
}
int add(int a, int b) {
int result = a + b;
if (result >= mod)
result -= mod;
return result;
}
int sub(int a, int b) {
int result = a - b;
if (result < 0)
result += mod;
return result;
}
int mult(int a, int b) { return (a * 1ll * b) % mod; }
int bin(int a, int n) {
int res = 1;
while (n) {
if (n & 1)
res = mult(res, a);
a = mult(a, a);
n /= 2;
}
return res;
}
int divv(int a, int b) { return mult(a, bin(b, mod - 2)); } | #include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forlr(i, l, r) for (int i = int(l); i <= int(r); i++)
#define repeat(n) for (int hjfjke = 0; hjfjke < int(n); hjfjke++)
#define all(c) c.begin(), c.end()
#define ll long long
const int mod = 1000000007;
inline int add(int a, int b);
inline int mult(int a, int b);
inline int sub(int a, int b);
inline int divv(int a, int b);
struct block {
int w, s, v;
bool operator<(block &other) { return s + w < other.s + other.w; }
};
int p[200500];
int c(int n, int k) { return divv(divv(p[n], p[k]), p[n - k]); }
int dp[3050];
int32_t main() {
std::iostream::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout << fixed << setprecision(10);
p[0] = 1;
for (int i = 1; i < 200500; i++)
p[i] = mult(p[i - 1], i);
int h, w;
cin >> h >> w;
vector<pair<int, int>> v;
v.emplace_back(h, w);
int n;
cin >> n;
while (n--) {
int r, c;
cin >> r >> c;
v.emplace_back(r, c);
}
sort(v.begin(), v.end());
forn(i, v.size()) {
int res = c(v[i].first + v[i].second - 2, v[i].first - 1);
forn(j, i) if (v[j].first <= v[i].first && v[j].second <= v[i].second) res =
sub(res,
mult(dp[j], c(v[i].first - v[j].first + v[i].second - v[j].second,
v[i].second - v[j].second)));
dp[i] = res;
// cout << res << endl;
}
cout << dp[v.size() - 1];
return 0;
}
int add(int a, int b) {
int result = a + b;
if (result >= mod)
result -= mod;
return result;
}
int sub(int a, int b) {
int result = a - b;
if (result < 0)
result += mod;
return result;
}
int mult(int a, int b) { return (a * 1ll * b) % mod; }
int bin(int a, int n) {
int res = 1;
while (n) {
if (n & 1)
res = mult(res, a);
a = mult(a, a);
n /= 2;
}
return res;
}
int divv(int a, int b) { return mult(a, bin(b, mod - 2)); } | [
"literal.number.change",
"variable_declaration.array_dimensions.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 987,359 | 987,360 | u503820274 | cpp |
p03184 | #include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define ll long long
using namespace std;
#define BUF_SIZE 1048576
char _buf[BUF_SIZE], *_is = _buf, *_it = _buf;
inline char rdc() {
if (_is == _it)
_it = (_is = _buf) + fread(_buf, 1, BUF_SIZE, stdin);
return *_is++;
}
inline void rdi(int &x) {
int f = 0;
register char ch = rdc();
while ((ch < '0' or ch > '9') and (ch ^ '-'))
ch = rdc();
if (ch == '-')
f = 1, ch = rdc();
while (ch >= '0' and ch <= '9')
x = (x << 3) + (x << 1) + (ch ^ '0'), ch = rdc();
if (f)
x = -x;
}
inline void write(int x) {
if (x < 0)
putchar('-'), x = -x;
if (x > 9)
write(x / 10);
putchar(x % 10 + '0');
}
inline void _write(int x) {
write(x);
putchar(' ');
}
inline void print(int x) {
write(x);
putchar('\n');
}
const int M = 1000005, MK = 20005;
const long long P = 1000000007;
long long fac[M], fac2[M], dp[M];
int n, m, K, x, y;
struct node {
int x, y;
inline bool operator<(const node &_) const {
if (x != _.x)
return x < _.x;
return y < _.y;
}
} A[MK];
inline int C(int K, int m) { return fac[K] * fac2[m] % P * fac2[K - m] % P; }
int main() {
fac[0] = fac2[0] = fac2[1] = 1;
for (int i = 1; i < M; ++i)
fac[i] = i * fac[i - 1] % P;
for (int i = 2; i < M; ++i)
fac2[i] = -P / i * fac2[P % i] % P;
for (int i = 1; i < M; ++i)
fac2[i] = fac2[i] * fac2[i - 1] % P;
cin >> n >> m >> K;
for (int i = 0; i < K; ++i)
cin >> A[i].x >> A[i].y;
sort(A, A + K);
A[K] = (node){n, m};
for (int i = 0; i <= K; ++i) {
dp[i] = C(A[i].x + A[i].y - 2, A[i].x - 1);
for (int j = 0; j < i; ++j) {
int x = A[i].x - A[j].x, y = A[i].y - A[j].y;
if (x >= 0 and y >= 0)
dp[i] = (dp[i] - dp[j] * C(x + y, x)) % P;
}
}
cout << dp[K] % P << endl;
return 0;
}
| #include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define ll long long
using namespace std;
#define BUF_SIZE 1048576
char _buf[BUF_SIZE], *_is = _buf, *_it = _buf;
inline char rdc() {
if (_is == _it)
_it = (_is = _buf) + fread(_buf, 1, BUF_SIZE, stdin);
return *_is++;
}
inline void rdi(int &x) {
int f = 0;
register char ch = rdc();
while ((ch < '0' or ch > '9') and (ch ^ '-'))
ch = rdc();
if (ch == '-')
f = 1, ch = rdc();
while (ch >= '0' and ch <= '9')
x = (x << 3) + (x << 1) + (ch ^ '0'), ch = rdc();
if (f)
x = -x;
}
inline void write(int x) {
if (x < 0)
putchar('-'), x = -x;
if (x > 9)
write(x / 10);
putchar(x % 10 + '0');
}
inline void _write(int x) {
write(x);
putchar(' ');
}
inline void print(int x) {
write(x);
putchar('\n');
}
const int M = 1000005, MK = 20005;
const long long P = 1000000007;
long long fac[M], fac2[M], dp[M];
int n, m, K, x, y;
struct node {
int x, y;
inline bool operator<(const node &_) const {
if (x != _.x)
return x < _.x;
return y < _.y;
}
} A[MK];
inline int C(int K, int m) { return fac[K] * fac2[m] % P * fac2[K - m] % P; }
int main() {
fac[0] = fac2[0] = fac2[1] = 1;
for (int i = 1; i < M; ++i)
fac[i] = i * fac[i - 1] % P;
for (int i = 2; i < M; ++i)
fac2[i] = -P / i * fac2[P % i] % P;
for (int i = 1; i < M; ++i)
fac2[i] = fac2[i] * fac2[i - 1] % P;
cin >> n >> m >> K;
for (int i = 0; i < K; ++i)
cin >> A[i].x >> A[i].y;
sort(A, A + K);
A[K] = (node){n, m};
for (int i = 0; i <= K; ++i) {
dp[i] = C(A[i].x + A[i].y - 2, A[i].x - 1);
for (int j = 0; j < i; ++j) {
int x = A[i].x - A[j].x, y = A[i].y - A[j].y;
if (x >= 0 and y >= 0)
dp[i] = (dp[i] - dp[j] * C(x + y, x)) % P;
}
}
cout << (dp[K] + P) % P << endl;
return 0;
}
| [] | 987,361 | 987,362 | u378667182 | cpp |
p03184 | #include <bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define ppf pop_front
#define umax(x, y) x = max(x, y)
#define umin(x, y) x = min(x, y)
#define ll long long
#define ii pair<int, int>
#define iii pair<ii, int>
#define iiii pair<ii, ii>
#define sz(x) ((int)x.size())
#define orta ((bas + son) >> 1)
#define all(x) x.begin(), x.end()
#define dbgs(x) cerr << (#x) << " --> " << (x) << " "
#define dbg(x) \
cerr << (#x) << " --> " << (x) << endl; \
getchar()
#define pw(x) (1 << (x))
#define inf 1000000005
#define MOD 1000000007
#define N 200005
#define M 27000
#define LOG 1000000
#define KOK 650
#define EPS 0.000000001
using namespace std;
int h, w, n, r, c;
int dp[N];
int f[N], inv[N];
int fe(int x, int y) {
if (y == 0)
return 1;
int res = fe(x, y >> 1);
res = 1ll * res * res % MOD;
if (y & 1)
res = 1ll * res * x % MOD;
return res;
}
int C(int x, int y) {
if (y > x || x < 0 || y < 0)
return 0;
return 1ll * f[x] * (1ll * inv[y] * inv[x - y] % MOD) % MOD;
}
void pre() {
int mx = h + w;
f[0] = inv[0] = 1;
for (int i = 1; i <= mx; i++) {
f[i] = 1ll * f[i - 1] * i % MOD;
inv[i] = fe(f[i], MOD - 2);
}
}
int main() {
// freopen("input.txt","r",stdin);
vector<ii> v;
scanf("%d %d %d", &h, &w, &n);
for (int i = 1; i <= n; i++) {
scanf("%d %d", &r, &c);
v.pb({r, c});
}
++n;
v.pb({h, w});
sort(all(v));
pre();
for (int i = 0; i < n; i++) {
auto x = v[i];
dp[i] = C(x.st + x.nd - 2, x.st - 1);
for (int j = 0; j < i; j++) {
auto y = v[j];
dp[i] = (1ll * dp[i] -
1ll * dp[j] * C(x.st - y.st + x.nd - y.nd, x.st - y.st) % MOD) %
MOD;
}
}
printf("%d", dp[n - 1]);
}
| #include <bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define ppf pop_front
#define umax(x, y) x = max(x, y)
#define umin(x, y) x = min(x, y)
#define ll long long
#define ii pair<int, int>
#define iii pair<ii, int>
#define iiii pair<ii, ii>
#define sz(x) ((int)x.size())
#define orta ((bas + son) >> 1)
#define all(x) x.begin(), x.end()
#define dbgs(x) cerr << (#x) << " --> " << (x) << " "
#define dbg(x) \
cerr << (#x) << " --> " << (x) << endl; \
getchar()
#define pw(x) (1 << (x))
#define inf 1000000005
#define MOD 1000000007
#define N 200005
#define M 27000
#define LOG 1000000
#define KOK 650
#define EPS 0.000000001
using namespace std;
int h, w, n, r, c;
int dp[N];
int f[N], inv[N];
int fe(int x, int y) {
if (y == 0)
return 1;
int res = fe(x, y >> 1);
res = 1ll * res * res % MOD;
if (y & 1)
res = 1ll * res * x % MOD;
return res;
}
int C(int x, int y) {
if (y > x || x < 0 || y < 0)
return 0;
return 1ll * f[x] * (1ll * inv[y] * inv[x - y] % MOD) % MOD;
}
void pre() {
int mx = h + w;
f[0] = inv[0] = 1;
for (int i = 1; i <= mx; i++) {
f[i] = 1ll * f[i - 1] * i % MOD;
inv[i] = fe(f[i], MOD - 2);
}
}
int main() {
// freopen("input.txt","r",stdin);
vector<ii> v;
scanf("%d %d %d", &h, &w, &n);
for (int i = 1; i <= n; i++) {
scanf("%d %d", &r, &c);
v.pb({r, c});
}
++n;
v.pb({h, w});
sort(all(v));
pre();
for (int i = 0; i < n; i++) {
auto x = v[i];
dp[i] = C(x.st + x.nd - 2, x.st - 1);
for (int j = 0; j < i; j++) {
auto y = v[j];
dp[i] = (1ll * dp[i] -
1ll * dp[j] * C(x.st - y.st + x.nd - y.nd, x.st - y.st) % MOD +
MOD) %
MOD;
}
}
printf("%d", dp[n - 1]);
}
| [] | 987,365 | 987,366 | u918828564 | cpp |
p03184 | #include <algorithm>
#include <iostream>
#include <utility>
using namespace std;
typedef long long ll;
ll mod = 1000000007, MAX = 100000, dp[3010][2] = {}, ans = 0;
pair<ll, ll> p[3010];
ll inv[100010], fact[100010], fi[100010];
void inverse() {
int i;
inv[1] = 1;
for (i = 2; i <= MAX; i++) {
inv[i] = mod - (mod / i) * inv[mod % i] % mod;
}
fact[0] = fi[0] = 1;
for (i = 1; i <= MAX; i++) {
fact[i] = fact[i - 1] * i % mod;
fi[i] = fi[i - 1] * inv[i] % mod;
}
}
ll comb(ll n, ll k) {
if (n < 0 || k < 0 || n < k) {
return 0;
} else {
return fact[n] * fi[k] % mod * fi[n - k] % mod;
}
}
int main() {
ll h, w, n, i, j;
cin >> h >> w >> n;
h--;
w--;
for (i = 0; i < n; i++) {
ll r, c;
cin >> r >> c;
r--;
c--;
p[i] = {r, c};
}
inverse();
p[n] = {0, 0};
sort(p, p + n + 1);
dp[0][0] = 1;
for (i = 1; i <= n; i++) {
for (j = 0; j < i; j++) {
if (p[j].first <= p[i].first && p[j].second <= p[i].second) {
ll x = p[i].first - p[j].first, y = p[i].second - p[j].second;
(dp[i][0] += comb(x + y, y) * dp[j][1]) %= mod;
(dp[i][1] += comb(x + y, y) * dp[j][0]) %= mod;
}
}
}
ll sum = 0;
for (i = 1; i <= n; i++) {
// cout << dp[i][1] << " " << dp[i][0] << endl;
ll x = h - p[i].first, y = w - p[i].second;
(sum += comb(x + y, y) * ((dp[i][1] - dp[i][0] + mod) % mod)) %= mod;
}
ans = (comb(h + w, h) - sum + mod) % mod;
cout << ans << endl;
// cout << comb(h+w,h) << " " <<
// comb(p[1].first+p[1].second,p[1].first)*comb(h - p[1].first + w -
// p[1].second,h - p[1].first)%mod << endl; cout << (comb(h+w,h) -
// comb(p[1].first+p[1].second,p[1].first)*comb(h - p[1].first + w -
// p[1].second,h - p[1].first)%mod + mod)%mod <<endl;
} | #include <algorithm>
#include <iostream>
#include <utility>
using namespace std;
typedef long long ll;
ll mod = 1000000007, MAX = 200000, dp[3010][2] = {}, ans = 0;
pair<ll, ll> p[3010];
ll inv[200010], fact[200010], fi[200010];
void inverse() {
int i;
inv[1] = 1;
for (i = 2; i <= MAX; i++) {
inv[i] = mod - (mod / i) * inv[mod % i] % mod;
}
fact[0] = fi[0] = 1;
for (i = 1; i <= MAX; i++) {
fact[i] = fact[i - 1] * i % mod;
fi[i] = fi[i - 1] * inv[i] % mod;
}
}
ll comb(ll n, ll k) {
if (n < 0 || k < 0 || n < k) {
return 0;
} else {
return fact[n] * fi[k] % mod * fi[n - k] % mod;
}
}
int main() {
ll h, w, n, i, j;
cin >> h >> w >> n;
h--;
w--;
for (i = 0; i < n; i++) {
ll r, c;
cin >> r >> c;
r--;
c--;
p[i] = {r, c};
}
inverse();
p[n] = {0, 0};
sort(p, p + n + 1);
dp[0][0] = 1;
for (i = 1; i <= n; i++) {
for (j = 0; j < i; j++) {
if (p[j].first <= p[i].first && p[j].second <= p[i].second) {
ll x = p[i].first - p[j].first, y = p[i].second - p[j].second;
(dp[i][0] += comb(x + y, y) * dp[j][1]) %= mod;
(dp[i][1] += comb(x + y, y) * dp[j][0]) %= mod;
}
}
}
ll sum = 0;
for (i = 1; i <= n; i++) {
ll x = h - p[i].first, y = w - p[i].second;
(sum += comb(x + y, y) * ((dp[i][1] - dp[i][0] + mod) % mod)) %= mod;
}
ans = (comb(h + w, h) - sum + mod) % mod;
cout << ans << endl;
} | [
"literal.number.change",
"variable_declaration.value.change",
"variable_declaration.array_dimensions.change"
] | 987,371 | 987,372 | u621509943 | cpp |
p03184 | #include <algorithm>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
const int mod = 1000000007;
long long inv[100100] = {0, 1}, fact[100100] = {1, 1}, ifact[100100] = {1, 1};
int H, W, N;
pair<int, int> P[3030];
long long D[3030];
int main() {
for (int i = 2; i < 100100; i++) {
inv[i] = (mod - mod / i) * inv[mod % i] % mod;
fact[i] = fact[i - 1] * i % mod;
ifact[i] = ifact[i - 1] * inv[i] % mod;
}
scanf("%d %d %d", &H, &W, &N);
for (int i = 0; i < N; i++)
scanf("%d %d", &P[i].first, &P[i].second);
P[N] = {1, 1};
P[N + 1] = {H, W};
N += 2;
sort(P, P + N);
D[0] = mod - 1;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++)
if (P[i].first <= P[j].first && P[i].second <= P[j].second) {
int dx = P[j].first - P[i].first;
int dy = P[j].second - P[i].second;
long long coeff = fact[dx + dy] * ifact[dx] % mod * ifact[dy] % mod;
D[j] = (D[j] + D[i] * (mod - coeff)) % mod;
}
}
printf("%lld\n", D[N - 1]);
return 0;
}
| #include <algorithm>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
const int mod = 1000000007;
long long inv[200200] = {0, 1}, fact[200200] = {1, 1}, ifact[200200] = {1, 1};
int H, W, N;
pair<int, int> P[3030];
long long D[3030];
int main() {
for (int i = 2; i < 200200; i++) {
inv[i] = (mod - mod / i) * inv[mod % i] % mod;
fact[i] = fact[i - 1] * i % mod;
ifact[i] = ifact[i - 1] * inv[i] % mod;
}
scanf("%d %d %d", &H, &W, &N);
for (int i = 0; i < N; i++)
scanf("%d %d", &P[i].first, &P[i].second);
P[N] = {1, 1};
P[N + 1] = {H, W};
N += 2;
sort(P, P + N);
D[0] = mod - 1;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++)
if (P[i].first <= P[j].first && P[i].second <= P[j].second) {
int dx = P[j].first - P[i].first;
int dy = P[j].second - P[i].second;
long long coeff = fact[dx + dy] * ifact[dx] % mod * ifact[dy] % mod;
D[j] = (D[j] + D[i] * (mod - coeff)) % mod;
}
}
printf("%lld\n", D[N - 1]);
return 0;
}
| [
"literal.number.change",
"variable_declaration.array_dimensions.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 987,381 | 987,382 | u233632872 | cpp |
p03185 | #include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAX_PIERRE = 2 * 1e5;
int nbPierre, cost;
int hauteur[MAX_PIERRE];
struct Ligne {
int coeffDirect, ordOrigine;
long double f(int x) { return coeffDirect * x + ordOrigine; }
long double intersecX(Ligne autre) {
return (ordOrigine - autre.ordOrigine) / (coeffDirect - autre.coeffDirect);
}
};
int32_t main() {
cin >> nbPierre >> cost;
deque<Ligne> cht;
int dp[nbPierre];
cin >> hauteur[0];
dp[0] = 0;
Ligne premier = {-2 * hauteur[0], cost + hauteur[0] * hauteur[0]};
cht.push_back(premier);
for (int i = 1; i < nbPierre; i++) {
cin >> hauteur[i];
while (cht.size() >= 2 && cht[0].f(hauteur[i]) >= cht[1].f(hauteur[i])) {
cht.pop_front();
}
int y = cht[0].f(hauteur[i]);
dp[i] = y + hauteur[i] * hauteur[i];
Ligne cur = {-2 * hauteur[i], cost + dp[i] + hauteur[i] * hauteur[i]};
while (cht.size() >= 2 &&
cur.intersecX(cht[cht.size() - 1]) <=
cht[cht.size() - 1].intersecX(cht[cht.size() - 2])) {
cht.pop_back();
}
cht.push_back(cur);
}
// for(int i = 0; i < nbPierre; i++) cout << dp[i] << endl;
cout << dp[nbPierre - 1];
return 0;
} | #include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAX_PIERRE = 2 * 1e5;
int nbPierre, cost;
int hauteur[MAX_PIERRE];
struct Ligne {
int coeffDirect, ordOrigine;
long double f(int x) { return coeffDirect * x + ordOrigine; }
long double intersecX(Ligne autre) {
return (ordOrigine - autre.ordOrigine) / (autre.coeffDirect - coeffDirect);
}
};
int32_t main() {
cin >> nbPierre >> cost;
deque<Ligne> cht;
int dp[nbPierre];
cin >> hauteur[0];
dp[0] = 0;
Ligne premier = {-2 * hauteur[0], cost + hauteur[0] * hauteur[0]};
cht.push_back(premier);
for (int i = 1; i < nbPierre; i++) {
cin >> hauteur[i];
while (cht.size() >= 2 && cht[0].f(hauteur[i]) >= cht[1].f(hauteur[i])) {
cht.pop_front();
}
int y = cht[0].f(hauteur[i]);
dp[i] = y + hauteur[i] * hauteur[i];
Ligne cur = {-2 * hauteur[i], cost + dp[i] + hauteur[i] * hauteur[i]};
while (cht.size() >= 2 &&
cur.intersecX(cht[cht.size() - 1]) <=
cht[cht.size() - 1].intersecX(cht[cht.size() - 2])) {
cht.pop_back();
}
cht.push_back(cur);
}
// for(int i = 0; i < nbPierre; i++) cout << dp[i] << endl;
cout << dp[nbPierre - 1];
return 0;
}
| [
"expression.operation.binary.remove"
] | 987,416 | 987,417 | u807305742 | cpp |
p03185 | #include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAX_PIERRE = 2 * 1e5;
int nbPierre, cost;
int hauteur[MAX_PIERRE];
struct Ligne {
int coeffDirect, ordOrigine;
long double f(int x) { return coeffDirect * x + ordOrigine; }
long double intersecX(Ligne autre) {
return (ordOrigine - autre.ordOrigine) / (coeffDirect - autre.coeffDirect);
}
};
int32_t main() {
cin >> nbPierre >> cost;
deque<Ligne> cht;
int dp[nbPierre];
cin >> hauteur[0];
dp[0] = 0;
Ligne premier = {-2 * hauteur[0], cost + hauteur[0] * hauteur[0]};
cht.push_back(premier);
for (int i = 1; i < nbPierre; i++) {
cin >> hauteur[i];
while (cht.size() >= 2 && cht[0].f(hauteur[i]) >= cht[1].f(hauteur[i])) {
cht.pop_front();
}
int y = cht[0].f(hauteur[i]);
dp[i] = y + hauteur[i] * hauteur[i];
Ligne cur = {-2 * hauteur[i], cost + dp[i] + hauteur[i] * hauteur[i]};
while (cht.size() >= 2 &&
cur.intersecX(cht[cht.size() - 1]) <=
cht[cht.size() - 1].intersecX(cht[cht.size() - 2])) {
cht.pop_front();
}
cht.push_back(cur);
}
// for(int i = 0; i < nbPierre; i++) cout << dp[i] << endl;
cout << dp[nbPierre - 1];
return 0;
}
| #include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAX_PIERRE = 2 * 1e5;
int nbPierre, cost;
int hauteur[MAX_PIERRE];
struct Ligne {
int coeffDirect, ordOrigine;
long double f(int x) { return coeffDirect * x + ordOrigine; }
long double intersecX(Ligne autre) {
return (ordOrigine - autre.ordOrigine) / (autre.coeffDirect - coeffDirect);
}
};
int32_t main() {
cin >> nbPierre >> cost;
deque<Ligne> cht;
int dp[nbPierre];
cin >> hauteur[0];
dp[0] = 0;
Ligne premier = {-2 * hauteur[0], cost + hauteur[0] * hauteur[0]};
cht.push_back(premier);
for (int i = 1; i < nbPierre; i++) {
cin >> hauteur[i];
while (cht.size() >= 2 && cht[0].f(hauteur[i]) >= cht[1].f(hauteur[i])) {
cht.pop_front();
}
int y = cht[0].f(hauteur[i]);
dp[i] = y + hauteur[i] * hauteur[i];
Ligne cur = {-2 * hauteur[i], cost + dp[i] + hauteur[i] * hauteur[i]};
while (cht.size() >= 2 &&
cur.intersecX(cht[cht.size() - 1]) <=
cht[cht.size() - 1].intersecX(cht[cht.size() - 2])) {
cht.pop_back();
}
cht.push_back(cur);
}
// for(int i = 0; i < nbPierre; i++) cout << dp[i] << endl;
cout << dp[nbPierre - 1];
return 0;
}
| [
"expression.operation.binary.remove",
"call.function.change"
] | 987,418 | 987,417 | u807305742 | cpp |
p03185 | #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(X) (X).begin(), (X).end()
#define REP(i, x, y) for (ll i = x; i <= y; ++i)
vector<string> vec_splitter(string s) {
for (char &c : s)
c = c == ',' ? ' ' : c;
stringstream ss;
ss << s;
vector<string> res;
for (string z; ss >> z; res.push_back(z))
;
return res;
}
void debug_out(vector<string> args, int idx) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, Head H, Tail... T) {
if (idx > 0)
cerr << ", ";
stringstream ss;
ss << H;
cerr << args[idx] << " = " << ss.str();
debug_out(args, idx + 1, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __VA_ARGS__)
void localTest() {
#ifndef ONLINE_JUDGE
freopen("inp", "r", stdin);
freopen("out", "w", stdout);
#endif
}
const ll N = 2e5 + 5, inf = 1e15, M = 1e6 + 5, MX = 1e6;
ll dp[N], n, b, A[N];
struct line {
ll m, c;
};
vector<line> T(4 * M, (line){0LL, inf});
ll getY(line l, ll x) { return l.m * x + l.c; }
void addLine(ll node, ll lo, ll hi, line l) {
if (lo > hi)
return;
ll mid = (lo + hi) >> 1LL;
bool leftVal = getY(l, lo) < getY(T[node], lo);
bool rightVal = getY(l, mid + 1) < getY(T[node], mid + 1);
if (rightVal)
swap(T[node], l);
if (lo == hi)
return;
if (leftVal != rightVal)
addLine(node << 1, lo, mid, l);
else
addLine(node << 1 | 1, mid + 1, hi, l);
return;
}
ll query(ll node, ll lo, ll hi, ll x) {
ll ans = getY(T[node], x);
if (lo >= hi)
return ans;
ll mid = (lo + hi) >> 1LL;
if (x <= mid)
return min(ans, query(node << 1, lo, mid, x));
else
return min(ans, query(node << 1 | 1, mid + 1, hi, x));
}
int main() {
localTest();
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> b;
for (ll i = 1; i <= n; ++i) {
cin >> A[i];
if (i > 1)
dp[i] = b + A[i] * A[i] + query(1, 1, MX, A[i]);
addLine(1, 1, MX, (line){-2 * A[i], dp[i] + A[i] * A[i]});
}
cout << dp[n] << "\n";
return 0;
} | #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(X) (X).begin(), (X).end()
#define REP(i, x, y) for (ll i = x; i <= y; ++i)
vector<string> vec_splitter(string s) {
for (char &c : s)
c = c == ',' ? ' ' : c;
stringstream ss;
ss << s;
vector<string> res;
for (string z; ss >> z; res.push_back(z))
;
return res;
}
void debug_out(vector<string> args, int idx) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, Head H, Tail... T) {
if (idx > 0)
cerr << ", ";
stringstream ss;
ss << H;
cerr << args[idx] << " = " << ss.str();
debug_out(args, idx + 1, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __VA_ARGS__)
void localTest() {
#ifndef ONLINE_JUDGE
freopen("inp", "r", stdin);
freopen("out", "w", stdout);
#endif
}
const ll N = 2e5 + 5, inf = 1e15, M = 1e6 + 5, MX = 1e6;
ll dp[N], n, b, A[N];
struct line {
ll m, c;
};
vector<line> T(4 * M, (line){0LL, inf});
ll getY(line l, ll x) { return l.m * x + l.c; }
void addLine(ll node, ll lo, ll hi, line l) {
if (lo > hi)
return;
ll mid = (lo + hi) >> 1LL;
bool leftVal = getY(l, lo) < getY(T[node], lo);
bool rightVal = getY(l, mid + 1) < getY(T[node], mid + 1);
if (rightVal)
swap(T[node], l);
if (lo == hi)
return;
if (leftVal != rightVal)
addLine(node << 1, lo, mid, l);
else
addLine(node << 1 | 1, mid + 1, hi, l);
return;
}
ll query(ll node, ll lo, ll hi, ll x) {
ll ans = getY(T[node], x);
if (lo >= hi)
return ans;
ll mid = (lo + hi) >> 1LL;
if (x <= mid)
return min(ans, query(node << 1, lo, mid, x));
else
return min(ans, query(node << 1 | 1, mid + 1, hi, x));
}
int main() {
// localTest();
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> b;
for (ll i = 1; i <= n; ++i) {
cin >> A[i];
if (i > 1)
dp[i] = b + A[i] * A[i] + query(1, 1, MX, A[i]);
addLine(1, 1, MX, (line){-2 * A[i], dp[i] + A[i] * A[i]});
}
cout << dp[n] << "\n";
return 0;
} | [
"call.remove"
] | 987,419 | 987,420 | u921436946 | cpp |
p03185 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define PB push_back
struct equation {
ll m, b; // y = m * x + b
ll y(ll x0) { return m * x0 + b; }
ld intersect(equation o) { return (ld)(o.b - b) / (m - o.m); }
};
struct CHT {
deque<equation> hull;
void add(const equation &e) {
while (hull.size() > 1 and hull.rbegin()[1].intersect(e) <
hull.rbegin()[1].intersect(hull.rbegin()[0]))
hull.pop_back();
hull.PB(e);
}
ll get(ll x0) {
if (!hull.empty())
return 0; // PS
while (hull.size() > 1 and hull[0].y(x0) > hull[1].y(x0))
hull.pop_front();
return hull[0].y(x0);
}
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
ll c;
cin >> n >> c;
vector<ll> a(n);
trav(i, a) cin >> i;
CHT cht;
vector<ll> dp(n);
cht.add({-2 * a[0], dp[0] + a[0] * a[0]});
rep(i, 1, n) {
dp[i] = cht.get(a[i]) + c + a[i] * a[i];
cht.add({-2 * a[i], dp[i] + a[i] * a[i]});
}
cout << dp[n - 1] << '\n';
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define PB push_back
struct equation {
ll m, b; // y = m * x + b
ll y(ll x0) { return m * x0 + b; }
ld intersect(equation o) { return (ld)(o.b - b) / (m - o.m); }
};
struct CHT {
deque<equation> hull;
void add(const equation &e) {
while (hull.size() > 1 and hull.rbegin()[1].intersect(e) <
hull.rbegin()[1].intersect(hull.rbegin()[0]))
hull.pop_back();
hull.PB(e);
}
ll get(ll x0) {
if (hull.empty())
return 0; // PS
while (hull.size() > 1 and hull[0].y(x0) > hull[1].y(x0))
hull.pop_front();
return hull[0].y(x0);
}
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
ll c;
cin >> n >> c;
vector<ll> a(n);
trav(i, a) cin >> i;
CHT cht;
vector<ll> dp(n);
cht.add({-2 * a[0], dp[0] + a[0] * a[0]});
rep(i, 1, n) {
dp[i] = cht.get(a[i]) + c + a[i] * a[i];
cht.add({-2 * a[i], dp[i] + a[i] * a[i]});
}
cout << dp[n - 1] << '\n';
}
| [
"expression.operation.unary.logical.remove",
"control_flow.branch.if.condition.change"
] | 987,430 | 987,431 | u092269433 | cpp |
p03185 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ll N = 2e5 + 5, INF = 1e18;
ll n, C, h[N], dp[N];
// x = (b2 - b1) / (k1 - k2)
struct Line {
ll k, b;
Line(ll kk, ll bb) {
k = kk;
b = bb;
}
};
vector<Line> lines;
ld cross(Line a, Line b) { return (b.b - a.b + 0.0) / (a.k - b.k + 0.0); }
ll get(ll x, Line temp) { return temp.k * x + temp.b; }
void add(Line new_line) {
while (lines.size() > 1) {
ll last = lines.size() - 1;
if (cross(lines[last - 1], new_line) >
cross(lines[last], lines[last - 1])) {
break;
}
lines.pop_back();
}
lines.push_back(new_line);
}
ll ternary(ll x) {
ll L = 0, R = lines.size() - 1, m1, m2, ans = INF;
while (R - L > 3) {
m1 = L + (R - L) / 2;
m2 = R - (R - L) / 2;
if (get(x, lines[m1]) < get(x, lines[m2])) {
L = m1;
} else {
R = m2;
}
}
for (ll i = L; i <= R; i++) {
ans = min(ans, get(x, lines[i]));
}
return ans;
}
// dp[i] = dp[j] + h[i]^2 - h[i]*h[j] + h[j]^2 + C
// dp[i] = -h[j] * h[i] + dp[j] + h[j]^2 + {h[i]^2 + C}
// y = -k * x + b
int main() {
cin >> n >> C;
for (ll i = 1; i <= n; i++) {
cin >> h[i];
}
add(Line(-2 * h[1], h[1] * h[1]));
for (ll i = 2; i <= n; i++) {
dp[i] = ternary(h[i]) + h[i] * h[i] + C;
add(Line(-2 * h[i], dp[i] + h[i] * h[i]));
}
cout << dp[n];
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ll N = 2e5 + 5, INF = 1e18;
ll n, C, h[N], dp[N];
// x = (b2 - b1) / (k1 - k2)
struct Line {
ll k, b;
Line(ll kk, ll bb) {
k = kk;
b = bb;
}
};
vector<Line> lines;
ld cross(Line a, Line b) { return (b.b - a.b + 0.0) / (a.k - b.k + 0.0); }
ll get(ll x, Line temp) { return temp.k * x + temp.b; }
void add(Line new_line) {
while (lines.size() > 1) {
ll last = lines.size() - 1;
if (cross(lines[last - 1], new_line) >
cross(lines[last], lines[last - 1])) {
break;
}
lines.pop_back();
}
lines.push_back(new_line);
}
ll ternary(ll x) {
ll L = 0, R = lines.size() - 1, m1, m2, ans = INF;
while (R - L > 3) {
m1 = L + (R - L) / 3;
m2 = R - (R - L) / 3;
if (get(x, lines[m1]) > get(x, lines[m2])) {
L = m1;
} else {
R = m2;
}
}
for (ll i = L; i <= R; i++) {
ans = min(ans, get(x, lines[i]));
}
return ans;
}
// dp[i] = dp[j] + h[i]^2 - h[i]*h[j] + h[j]^2 + C
// dp[i] = -h[j] * h[i] + dp[j] + h[j]^2 + {h[i]^2 + C}
// y = -k * x + b
int main() {
cin >> n >> C;
for (ll i = 1; i <= n; i++) {
cin >> h[i];
}
add(Line(-2 * h[1], h[1] * h[1]));
for (ll i = 2; i <= n; i++) {
dp[i] = ternary(h[i]) + h[i] * h[i] + C;
add(Line(-2 * h[i], dp[i] + h[i] * h[i]));
}
cout << dp[n];
return 0;
} | [
"literal.number.change",
"assignment.value.change",
"expression.operation.binary.change",
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 987,432 | 987,433 | u967326959 | cpp |
p03185 | /*dp[n] = 0;
for(ll i = n-1; i >= 1; --i){
dp[i] = INF;
for(ll j = i+1; j <= n; ++j){
dp[i] = min(dp[i], dp[j] + (a[i]-a[j])*(a[i]-a[j]) + c);
}
}
cout<<dp[1];*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18, N = 200005;
ll n, c, a[N], dp[N];
struct L {
ll a, b;
ll value(ll x) { return a * x + b; }
pair<ll, ll> intersect(const L &temp) const {
ll one = temp.b - b;
ll two = a - temp.a;
if (two < 0) {
two *= -1;
one *= -1;
}
return {one, two};
}
};
int main() {
cin >> n >> c;
for (ll i = 1; i < n; i++) {
cin >> a[i];
}
vector<L> lines;
ll start = 0;
for (ll i = 0; i < n; i++) {
while (start <= (ll)lines.size() - 2) {
L A = lines[start];
L B = lines[start + 1];
if (A.value(a[i]) >= B.value(a[i])) {
start++;
} else {
break;
}
}
ll best = 0;
if (i != 0) {
best = lines[start].value(a[i]) + a[i] * a[i] + c;
}
L line = {-2 * a[i], best + a[i] * a[i]};
while (start <= (ll)lines.size() - 2) {
L A = lines[(ll)lines.size() - 2];
L B = lines[(ll)lines.size() - 1];
pair<ll, ll> one = A.intersect(B);
pair<ll, ll> two = B.intersect(line);
if ((__int128)one.first * two.second >=
(__int128)one.second * two.first) {
lines.pop_back();
} else {
break;
}
}
lines.push_back(line);
if (i == n - 1) {
cout << best;
}
}
return 0;
} | /*dp[n] = 0;
for(ll i = n-1; i >= 1; --i){
dp[i] = INF;
for(ll j = i+1; j <= n; ++j){
dp[i] = min(dp[i], dp[j] + (a[i]-a[j])*(a[i]-a[j]) + c);
}
}
cout<<dp[1];*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18, N = 200005;
ll n, c, a[N], dp[N];
struct L {
ll a, b;
ll value(ll x) { return a * x + b; }
pair<ll, ll> intersect(const L &temp) const {
ll one = temp.b - b;
ll two = a - temp.a;
if (two < 0) {
two *= -1;
one *= -1;
}
return {one, two};
}
};
int main() {
cin >> n >> c;
for (ll i = 0; i < n; i++) {
cin >> a[i];
}
vector<L> lines;
ll start = 0;
for (ll i = 0; i < n; i++) {
while (start <= (ll)lines.size() - 2) {
L A = lines[start];
L B = lines[start + 1];
if (A.value(a[i]) >= B.value(a[i])) {
start++;
} else {
break;
}
}
ll best = 0;
if (i != 0) {
best = lines[start].value(a[i]) + a[i] * a[i] + c;
}
L line = {-2 * a[i], best + a[i] * a[i]};
while (start <= (ll)lines.size() - 2) {
L A = lines[(ll)lines.size() - 2];
L B = lines[(ll)lines.size() - 1];
pair<ll, ll> one = A.intersect(B);
pair<ll, ll> two = B.intersect(line);
if ((__int128)one.first * two.second >=
(__int128)one.second * two.first) {
lines.pop_back();
} else {
break;
}
}
lines.push_back(line);
if (i == n - 1) {
cout << best;
}
}
return 0;
} | [
"literal.number.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one"
] | 987,434 | 987,435 | u967326959 | cpp |
p03185 | #include <bits/stdc++.h>
using namespace std;
// base:[Convex-Hull Trick -
// sataniC++](http://satanic0258.hatenablog.com/entry/2016/08/16/181331#fn-534591c8)
//追加する直線の傾きは単調(最小値なら傾きは単調減少、最大値なら傾きは単調増加)
template <typename T> struct ConvecHullTrick {
typedef pair<T, T> Line;
vector<Line> lines; //直線(傾き,切片)
bool isMonotonicX; //最小値(最大値)を求めるxが単調であるか
function<bool(T l, T r)> comp; //最小/最大を判断する関数
// flag:クエリは単調? compFunc:求めるのは最大値?
ConvecHullTrick(bool flagX = 0, bool compFunc = 0) : isMonotonicX(flagX) {
if (compFunc)
comp = [](T l, T r) { return l <= r; };
else
comp = [](T l, T r) { return l >= r; };
};
//直線l1,l2,l3のうちl2が不必要であるかどうか
bool check(Line l1, Line l2, Line l3) {
if (l1 < l3)
swap(l1, l3);
T a1 = l1.first, a2 = l2.first, a3 = l3.first, b1 = l1.second,
b2 = l2.second, b3 = l3.second;
return (b3 - b2) * (a2 - a1) >= (b2 - b1) * (a3 - a2);
}
//直線y=ax+bを追加する 単調性から付け足すのは一番後ろで、不必要なやつが消えるまで一番後ろを消したら付け足す
void add(T a, T b) {
Line line(a, b);
while (lines.size() >= 2 && check(*(lines.end() - 2), lines.back(), line))
lines.pop_back();
lines.emplace_back(line);
}
// linesのi番目の直線のxでの値
T f(int i, T x) { return lines[i].first * x + lines[i].second; }
//特定のlineのxでの値
T f(Line line, T x) { return line.first * x + line.second; }
//直線群の中でxの時に最小(最大)となる値を返す
T get(T x) {
assert(lines.size());
if (isMonotonicX) { //最小値(最大値)クエリにおけるxが単調(昇順)
static int head = 0;
while (lines.size() - head >= 2 && comp(f(head, x), f(head + 1, x)))
head++;
return f(head, x);
} else {
int low = -1, high = lines.size() - 1;
while (high - low > 1) {
int mid = (high + low) >> 1;
if (comp(f(mid, x), f(mid + 1, x)))
low = mid;
else
high = mid;
}
return f(high, x);
}
}
};
long long dp[223456];
int main() {
long long n, c;
cin >> n >> c;
ConvecHullTrick<long long> CHT(1, 0);
for (int i = 0; i < n; i++) {
long long h;
cin >> h;
int res = 0;
if (i)
res = CHT.get(h) + h * h + c;
if (i == n - 1)
cout << res << endl;
else
CHT.add(-2 * h, res + h * h);
}
}
| #include <bits/stdc++.h>
using namespace std;
// base:[Convex-Hull Trick -
// sataniC++](http://satanic0258.hatenablog.com/entry/2016/08/16/181331#fn-534591c8)
//追加する直線の傾きは単調(最小値なら傾きは単調減少、最大値なら傾きは単調増加)
template <typename T> struct ConvecHullTrick {
typedef pair<T, T> Line;
vector<Line> lines; //直線(傾き,切片)
bool isMonotonicX; //最小値(最大値)を求めるxが単調であるか
function<bool(T l, T r)> comp; //最小/最大を判断する関数
// flag:クエリは単調? compFunc:求めるのは最大値?
ConvecHullTrick(bool flagX = 0, bool compFunc = 0) : isMonotonicX(flagX) {
if (compFunc)
comp = [](T l, T r) { return l <= r; };
else
comp = [](T l, T r) { return l >= r; };
};
//直線l1,l2,l3のうちl2が不必要であるかどうか
bool check(Line l1, Line l2, Line l3) {
if (l1 < l3)
swap(l1, l3);
T a1 = l1.first, a2 = l2.first, a3 = l3.first, b1 = l1.second,
b2 = l2.second, b3 = l3.second;
return (b3 - b2) * (a2 - a1) >= (b2 - b1) * (a3 - a2);
}
//直線y=ax+bを追加する 単調性から付け足すのは一番後ろで、不必要なやつが消えるまで一番後ろを消したら付け足す
void add(T a, T b) {
Line line(a, b);
while (lines.size() >= 2 && check(*(lines.end() - 2), lines.back(), line))
lines.pop_back();
lines.emplace_back(line);
}
// linesのi番目の直線のxでの値
T f(int i, T x) { return lines[i].first * x + lines[i].second; }
//特定のlineのxでの値
T f(Line line, T x) { return line.first * x + line.second; }
//直線群の中でxの時に最小(最大)となる値を返す
T get(T x) {
assert(lines.size());
if (isMonotonicX) { //最小値(最大値)クエリにおけるxが単調(昇順)
static int head = 0;
while (lines.size() - head >= 2 && comp(f(head, x), f(head + 1, x)))
head++;
return f(head, x);
} else {
int low = -1, high = lines.size() - 1;
while (high - low > 1) {
int mid = (high + low) >> 1;
if (comp(f(mid, x), f(mid + 1, x)))
low = mid;
else
high = mid;
}
return f(high, x);
}
}
};
long long dp[223456];
int main() {
long long n, c;
cin >> n >> c;
ConvecHullTrick<long long> CHT(1, 0);
for (int i = 0; i < n; i++) {
long long h;
cin >> h;
long long res = 0;
if (i)
res = CHT.get(h) + h * h + c;
if (i == n - 1)
cout << res << endl;
else
CHT.add(-2 * h, res + h * h);
}
}
| [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 987,438 | 987,439 | u942774736 | cpp |
p03185 | #include <deque>
#include <iostream>
using namespace std;
const int NMAX = 2e5;
struct Line {
long long a, b;
long long eval(long long x) { return a * x + b; }
};
int N, C;
long long h[NMAX + 5];
long long minCost[NMAX + 5];
deque<Line> dq;
bool LinesAreGood(Line l1, Line l2, Line l3) {
/// lines are good <=> getx(l1, l2) < getx(l2, l3)
return (l2.b - l1.b) * (l2.a - l3.a) < (l1.a - l2.a) * (l3.b - l2.b);
}
void Insert(Line l) {
while (dq.size() > 1 && !LinesAreGood(dq.end()[-2], dq.end()[-1], l))
dq.pop_back();
dq.push_back(l);
}
double xIntersect(Line l1, Line l2) {
return 1.0 * (l2.b - l1.b) / (l1.a - l2.a);
}
long long QueryMin(long long x) {
while (dq.size() > 1 && xIntersect(dq[0], dq[1]) < x)
dq.pop_front();
return dq[0].eval(x);
}
int main() {
cin >> N >> C;
for (int i = 1; i <= N; i++)
cin >> h[i];
minCost[1] = 0;
for (int i = 2; i <= N; i++) {
Insert({-2 * h[i - 1], minCost[i - 1] + h[i - 1] * h[i - 1]});
minCost[i] = C + h[i] * h[i] + QueryMin(h[i]);
}
cout << minCost[N] << '\n';
return 0;
}
| #include <deque>
#include <iostream>
using namespace std;
const int NMAX = 2e5;
struct Line {
long long a, b;
long long eval(long long x) { return a * x + b; }
};
long long N, C;
long long h[NMAX + 5];
long long minCost[NMAX + 5];
deque<Line> dq;
bool LinesAreGood(Line l1, Line l2, Line l3) {
/// lines are good <=> getx(l1, l2) < getx(l2, l3)
return (l2.b - l1.b) * (l2.a - l3.a) < (l1.a - l2.a) * (l3.b - l2.b);
}
void Insert(Line l) {
while (dq.size() > 1 && !LinesAreGood(dq.end()[-2], dq.end()[-1], l))
dq.pop_back();
dq.push_back(l);
}
double xIntersect(Line l1, Line l2) {
return 1.0 * (l2.b - l1.b) / (l1.a - l2.a);
}
long long QueryMin(long long x) {
while (dq.size() > 1 && xIntersect(dq[0], dq[1]) < x)
dq.pop_front();
return dq[0].eval(x);
}
int main() {
cin >> N >> C;
for (int i = 1; i <= N; i++)
cin >> h[i];
minCost[1] = 0;
for (int i = 2; i <= N; i++) {
Insert({-2 * h[i - 1], minCost[i - 1] + h[i - 1] * h[i - 1]});
minCost[i] = C + h[i] * h[i] + QueryMin(h[i]);
}
cout << minCost[N] << '\n';
return 0;
}
| [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 987,456 | 987,457 | u323394394 | cpp |
p03185 | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 2e5 + 10;
LL h[MAXN], dp[MAXN];
int n, c;
deque<int> que;
double slope(int j, int k) {
return double((dp[j] + h[j] * 1ll * h[j]) - (dp[k] + h[k] * 1ll * h[k])) /
(2ll * h[j] - 2ll * h[k]);
}
int main() {
cin >> n >> c;
for (int i = 1; i <= n; i++)
cin >> h[i];
que.push_front(1);
for (int i = 2; i <= n; i++) {
while (que.size() > 1 && slope(que[0], que[1]) <= h[i]) {
que.pop_front();
}
int j = que[0];
dp[i] = dp[j] + (h[i] - h[j]) * (h[i] - h[j]) + c;
int sz = que.size();
while (sz > 1 && slope(que[sz - 1], que[sz - 2]) >= slope(que[sz - 1], i)) {
que.pop_back();
sz = que.size();
}
que.push_back(i);
}
cout << dp[n] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 2e5 + 10;
LL h[MAXN], dp[MAXN];
LL n, c;
deque<int> que;
double slope(int j, int k) {
return double((dp[j] + h[j] * 1ll * h[j]) - (dp[k] + h[k] * 1ll * h[k])) /
(2ll * h[j] - 2ll * h[k]);
}
int main() {
cin >> n >> c;
for (int i = 1; i <= n; i++)
cin >> h[i];
que.push_front(1);
for (int i = 2; i <= n; i++) {
while (que.size() > 1 && slope(que[0], que[1]) <= h[i]) {
que.pop_front();
}
int j = que[0];
dp[i] = dp[j] + (h[i] - h[j]) * (h[i] - h[j]) + c;
int sz = que.size();
while (sz > 1 && slope(que[sz - 1], que[sz - 2]) >= slope(que[sz - 1], i)) {
que.pop_back();
sz = que.size();
}
que.push_back(i);
}
cout << dp[n] << endl;
return 0;
}
| [
"variable_declaration.type.change"
] | 987,462 | 987,463 | u470165280 | cpp |
p03185 | #include <iostream>
#include <vector>
using namespace std;
class line {
public:
long long a;
long long b;
line() { ; }
line(long long A, long long B) {
a = A;
b = B;
}
long long eval(long long x) { return a * x + b; }
};
vector<line> L;
void insert(line k) {
if (L.size() <= 1)
L.push_back(k);
else {
line l1 = L[L.size() - 2];
line l2 = L[L.size() - 1];
if ((l2.b - l1.b) * (l1.a - l2.a) >= (l2.b - k.b) / (k.a - l2.a)) {
L.pop_back();
insert(k);
} else
L.push_back(k);
}
}
long long b_search(long long x, long long a, long long b) {
if (a == b)
return L[a].eval(x);
long long m = (a + b) / 2;
if ((L[m + 1].b - L[m].b) < x * (L[m].a - L[m + 1].a))
return b_search(x, m + 1, b);
else
return b_search(x, a, m);
}
int main() {
long long N, C;
cin >> N >> C;
long long h[N + 1];
for (long long i = 1; i <= N; i++)
cin >> h[i];
long long DP[N + 1];
DP[1] = 0;
insert(line(-2 * h[1], h[1] * h[1]));
for (long long i = 2; i <= N; i++) {
DP[i] = C + h[i] * h[i] + b_search(h[i], 0, L.size() - 1);
insert(line(-2 * h[i], DP[i] + h[i] * h[i]));
}
cout << DP[N] << '\n';
return 0;
// DP[1] = 0;
// DP[i] = C + h[i]^2 + min{1 <= j < i; (-2*h[j])*h[i] + (DP[j] + h[j]^2)}
} | #include <iostream>
#include <vector>
using namespace std;
class line {
public:
long long a;
long long b;
line() { ; }
line(long long A, long long B) {
a = A;
b = B;
}
long long eval(long long x) { return a * x + b; }
};
vector<line> L;
void insert(line k) {
if (L.size() <= 1)
L.push_back(k);
else {
line l1 = L[L.size() - 2];
line l2 = L[L.size() - 1];
if ((l2.b - l1.b) / (l1.a - l2.a) >= (l2.b - k.b) / (k.a - l2.a)) {
L.pop_back();
insert(k);
} else
L.push_back(k);
}
}
long long b_search(long long x, long long a, long long b) {
if (a == b)
return L[a].eval(x);
long long m = (a + b) / 2;
if ((L[m + 1].b - L[m].b) < x * (L[m].a - L[m + 1].a))
return b_search(x, m + 1, b);
else
return b_search(x, a, m);
}
int main() {
long long N, C;
cin >> N >> C;
long long h[N + 1];
for (long long i = 1; i <= N; i++)
cin >> h[i];
long long DP[N + 1];
DP[1] = 0;
insert(line(-2 * h[1], h[1] * h[1]));
for (long long i = 2; i <= N; i++) {
DP[i] = C + h[i] * h[i] + b_search(h[i], 0, L.size() - 1);
insert(line(-2 * h[i], DP[i] + h[i] * h[i]));
}
cout << DP[N] << '\n';
return 0;
// DP[1] = 0;
// DP[i] = C + h[i]^2 + min{1 <= j < i; (-2*h[j])*h[i] + (DP[j] + h[j]^2)}
} | [
"expression.operator.arithmetic.change",
"control_flow.branch.if.condition.change"
] | 987,474 | 987,475 | u404734036 | cpp |
p03185 | #include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdint>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <sys/timeb.h>
#include <vector>
using namespace std;
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define reprev(i, n) reprrev(i, 0, n)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define chmin(mi, val) mi = min(mi, val)
#define chmax(ma, val) ma = max(ma, val)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFR INT_MAX
#define INFL (long long)(4e18)
#define INFLR LLONG_MAX
#define EPS (1e-10)
#define MOD 1000000007
//#define MOD 998244353
#define PI 3.141592653589793238
#define RMAX 4294967295
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vvvvi = vector<vector<vector<vector<int>>>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvc = vector<vector<char>>;
using vs = vector<string>;
using vvs = vector<vector<string>>;
using Pi = pair<int, int>;
using vPi = vector<Pi>;
using vvPi = vector<vector<Pi>>;
using vvvPi = vector<vector<vector<Pi>>>;
using vvvvPi = vector<vector<vector<vector<Pi>>>>;
using Pll = pair<ll, ll>;
using vPll = vector<Pll>;
using Pd = pair<double, double>;
using vPd = vector<Pd>;
template <class T> using vec = vector<T>;
template <class T> using pql = priority_queue<T, vector<T>, greater<T>>;
using Comp = complex<double>;
// vvvvvvvvvvvvvvvvvvvvvvv debug output vvvvvvvvvvvvvvvvvvvvvvv
// vector
template <typename T> istream &operator>>(istream &is, const vector<T> &vec) {
for (T &x : vec)
is >> x;
return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &pair_var) {
os << "(" << pair_var.first << ", " << pair_var.second << ")";
return os;
}
// vector
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "{";
for (int i = 0; i < vec.size(); i++) {
os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
}
os << "}";
return os;
}
// deque
template <typename T> ostream &operator<<(ostream &os, const deque<T> &vec) {
os << "{";
for (int i = 0; i < vec.size(); i++) {
os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
}
os << "}";
return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
os << "{";
repi(itr, map_var) {
os << *itr;
itr++;
if (itr != map_var.end())
os << ", ";
itr--;
}
os << "}";
return os;
}
// set
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
os << "{";
repi(itr, set_var) {
os << *itr;
itr++;
if (itr != set_var.end())
os << ", ";
itr--;
}
os << "}";
return os;
}
// multiset
template <typename T>
ostream &operator<<(ostream &os, const multiset<T> &set_var) {
os << "{";
repi(itr, set_var) {
os << *itr;
itr++;
if (itr != set_var.end())
os << ", ";
itr--;
}
os << "}";
return os;
}
#define DUMPOUT cerr
void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&...tail) {
DUMPOUT << head;
if (sizeof...(Tail) > 0) {
DUMPOUT << ", ";
}
dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define dump(...) \
DUMPOUT << " " << string(#__VA_ARGS__) << ": " \
<< "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
<< " ", \
dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
// ^^^^^^^^^^^^^^^^^^^^^^^ debug output ^^^^^^^^^^^^^^^^^^^^^^^
string YN(bool y, int id = 0) {
if (id)
cout << id;
return (y ? "YES" : "NO");
}
string yn(bool y, int id = 0) {
if (id)
cout << id;
return (y ? "Yes" : "No");
}
string ON(bool y, int id = 0) {
if (id)
cout << id;
return (y ? "OK" : "NG");
}
int dir4[4][2] = {{0, -1}, {-1, 0}, {1, 0}, {0, 1}};
int dir8[8][2] = {{-1, -1}, {0, -1}, {1, -1}, {-1, 0},
{1, 0}, {-1, 1}, {0, 1}, {1, 1}};
char dirchar[4] = {'<', '^', '>', 'v'};
// [a,b)
int irand(int a, int b) {
static mt19937 Rand(static_cast<unsigned int>(time(nullptr)));
uniform_int_distribution<int> dist(a, b - 1);
return dist(Rand);
}
// [a,b)
double drand(int a, int b) {
static mt19937 Rand(static_cast<unsigned int>(time(nullptr)));
uniform_real_distribution<double> dist(a, b);
return dist(Rand);
}
// https://qiita.com/IgnorantCoder/items/3101d6276e9bdddf872c
template <typename A, typename F> inline auto transform(const A &v, F &&f) {
using result_type =
decltype(std::declval<F>()(std::declval<typename A::value_type>()));
vector<result_type> y(v.size());
std::transform(std::cbegin(v), std::cend(v), std::begin(y), f);
return y;
}
// 多次元vector生成
template <class T> vector<T> make_v(size_t size, const T &init) {
return vector<T>(size, init);
}
template <class... Ts> auto make_v(size_t size, Ts... rest) {
return vector<decltype(make_v(rest...))>(size, make_v(rest...));
}
template <typename T> T Max(vector<T> a) { return *max_element(all(a)); }
template <typename T> T Min(vector<T> a) { return *min_element(all(a)); }
template <typename T> T Sum(vector<T> a) { return accumulate(all(a), (T)0); }
// mapでカウントとかする
template <typename T> void Add(map<T, int> &m, T item) {
if (m.find(item) == m.end()) {
m[item] = 1;
} else {
m[item]++;
}
}
// mapでカウントとかする
template <typename T> void Erase(map<T, int> &m, T item) {
if (m.find(item) == m.end()) {
} else {
if (m[item] == 1) {
m.erase(item);
} else {
m[item]--;
}
}
}
// デフォルト値つきのmapのget
template <typename T, typename U> U Get(map<T, U> m, T key, U def) {
if (m.find(key) == m.end()) {
return def;
} else {
return m[key];
}
}
template <typename T> inline bool Contains(const set<T> &t, const T &key) {
return t.find(key) != t.end();
}
template <typename T, typename U>
inline bool Contains(const map<T, U> &t, const T &key) {
return t.find(key) != t.end();
}
template <class T> struct Edge {
int from, to;
T cost;
bool operator<(Edge e) { return cost < e.cost; }
};
template <class T> ostream &operator<<(ostream &os, Edge<T> &edge) {
os << "(" << edge.from << "->" << edge.to << ":" << edge.cost << ")";
return os;
}
template <class T = int> class Graph {
int n;
bool directed;
vector<vector<Edge<T>>> edges;
public:
Graph(int n, bool directed)
: n(n), directed(directed), edges(vector<vector<Edge<T>>>(n)) {}
void add_edge(int s, int t, T cost) {
edges[s].push_back(Edge<T>{s, t, cost});
if (!directed) {
edges[t].push_back(Edge<T>{t, s, cost});
}
}
Graph() {}
vector<Edge<T>> operator[](size_t i) const { return edges[i]; }
int size() const { return n; }
};
//======================================================
template <class T> class ConvesHullTrick {
static const T IS_QUERY = std::numeric_limits<T>::lowest();
struct Line {
T a, b;
// Lines において次の直線のポインタを得る
mutable std::function<const Line *()> nextLine;
bool operator<(Line rhs) const {
if (b == IS_QUERY) {
// 自分がクエリ
const Line *next_line = rhs.nextLine();
if (next_line == nullptr)
return false;
T x = a;
return (rhs.a - next_line->a) * x + (rhs.b - next_line->b) > 0;
} else if (rhs.b == IS_QUERY) {
// rhs がクエリ
const Line *next_line = nextLine();
if (next_line == nullptr)
return false;
T x = rhs.a;
return (a - next_line->a) * x + (b - next_line->b) > 0;
}
return (a < rhs.a || (a == rhs.a && b < rhs.b));
}
};
set<Line> lines; // 直線集合
bool isVain(Line l) {
dump(l.a, l.b);
// l が不要か判定
auto it = lines.find(l);
auto next_it = next(it);
if (it == lines.begin()) {
if (next_it == lines.end())
return false;
return it->a == next_it->a && it->b <= next_it->b;
} else {
auto prev_it = prev(it);
if (next_it == lines.end())
return it->a == prev_it->a && it->b <= prev_it->b;
return (prev_it->b - it->b) * (it->a - next_it->a) >=
(it->b - next_it->b) * (prev_it->a - it->a);
}
}
public:
void add(T a, T b) {
// 直線 ax+b を追加
auto it = lines.insert(Line{a, b}).first;
// 次の直線を得る関数をセットしておく
it->nextLine = [=] {
return (std::next(it) == lines.end() ? nullptr : &*std::next(it));
};
if (isVain(*it)) {
// 今追加した直線が不要
lines.erase(it);
return;
}
while (next(it) != lines.end() && isVain(*next(it))) {
lines.erase(next(it));
}
while (it != lines.begin() && isVain(*prev(it))) {
lines.erase(prev(it));
}
dump(a, b);
DEB {
for (auto l : lines) {
cerr << l.a << "x+ " << l.b << endl;
}
}
}
T get(T x) {
// x での最小値を出力
auto l = lines.lower_bound(Line{x, IS_QUERY});
dump(x, l->a * x + l->b);
return l->a * x + l->b;
}
};
int main() {
int N, C;
cin >> N >> C;
ConvesHullTrick<ll> CHT;
vll dp(N);
dp[0] = 0;
rep(i, N) {
int h;
cin >> h;
if (i != 0) {
dp[i] = CHT.get(h) + C + h * h;
dump(i, dp[i]);
}
CHT.add(-2 * h, h * h + dp[i]);
}
cout << dp[N - 1] << endl;
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdint>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <sys/timeb.h>
#include <vector>
using namespace std;
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define reprev(i, n) reprrev(i, 0, n)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define chmin(mi, val) mi = min(mi, val)
#define chmax(ma, val) ma = max(ma, val)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFR INT_MAX
#define INFL (long long)(4e18)
#define INFLR LLONG_MAX
#define EPS (1e-10)
#define MOD 1000000007
//#define MOD 998244353
#define PI 3.141592653589793238
#define RMAX 4294967295
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vvvvi = vector<vector<vector<vector<int>>>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvc = vector<vector<char>>;
using vs = vector<string>;
using vvs = vector<vector<string>>;
using Pi = pair<int, int>;
using vPi = vector<Pi>;
using vvPi = vector<vector<Pi>>;
using vvvPi = vector<vector<vector<Pi>>>;
using vvvvPi = vector<vector<vector<vector<Pi>>>>;
using Pll = pair<ll, ll>;
using vPll = vector<Pll>;
using Pd = pair<double, double>;
using vPd = vector<Pd>;
template <class T> using vec = vector<T>;
template <class T> using pql = priority_queue<T, vector<T>, greater<T>>;
using Comp = complex<double>;
// vvvvvvvvvvvvvvvvvvvvvvv debug output vvvvvvvvvvvvvvvvvvvvvvv
// vector
template <typename T> istream &operator>>(istream &is, const vector<T> &vec) {
for (T &x : vec)
is >> x;
return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &pair_var) {
os << "(" << pair_var.first << ", " << pair_var.second << ")";
return os;
}
// vector
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "{";
for (int i = 0; i < vec.size(); i++) {
os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
}
os << "}";
return os;
}
// deque
template <typename T> ostream &operator<<(ostream &os, const deque<T> &vec) {
os << "{";
for (int i = 0; i < vec.size(); i++) {
os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
}
os << "}";
return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
os << "{";
repi(itr, map_var) {
os << *itr;
itr++;
if (itr != map_var.end())
os << ", ";
itr--;
}
os << "}";
return os;
}
// set
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
os << "{";
repi(itr, set_var) {
os << *itr;
itr++;
if (itr != set_var.end())
os << ", ";
itr--;
}
os << "}";
return os;
}
// multiset
template <typename T>
ostream &operator<<(ostream &os, const multiset<T> &set_var) {
os << "{";
repi(itr, set_var) {
os << *itr;
itr++;
if (itr != set_var.end())
os << ", ";
itr--;
}
os << "}";
return os;
}
#define DUMPOUT cerr
void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&...tail) {
DUMPOUT << head;
if (sizeof...(Tail) > 0) {
DUMPOUT << ", ";
}
dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define dump(...) \
DUMPOUT << " " << string(#__VA_ARGS__) << ": " \
<< "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
<< " ", \
dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
// ^^^^^^^^^^^^^^^^^^^^^^^ debug output ^^^^^^^^^^^^^^^^^^^^^^^
string YN(bool y, int id = 0) {
if (id)
cout << id;
return (y ? "YES" : "NO");
}
string yn(bool y, int id = 0) {
if (id)
cout << id;
return (y ? "Yes" : "No");
}
string ON(bool y, int id = 0) {
if (id)
cout << id;
return (y ? "OK" : "NG");
}
int dir4[4][2] = {{0, -1}, {-1, 0}, {1, 0}, {0, 1}};
int dir8[8][2] = {{-1, -1}, {0, -1}, {1, -1}, {-1, 0},
{1, 0}, {-1, 1}, {0, 1}, {1, 1}};
char dirchar[4] = {'<', '^', '>', 'v'};
// [a,b)
int irand(int a, int b) {
static mt19937 Rand(static_cast<unsigned int>(time(nullptr)));
uniform_int_distribution<int> dist(a, b - 1);
return dist(Rand);
}
// [a,b)
double drand(int a, int b) {
static mt19937 Rand(static_cast<unsigned int>(time(nullptr)));
uniform_real_distribution<double> dist(a, b);
return dist(Rand);
}
// https://qiita.com/IgnorantCoder/items/3101d6276e9bdddf872c
template <typename A, typename F> inline auto transform(const A &v, F &&f) {
using result_type =
decltype(std::declval<F>()(std::declval<typename A::value_type>()));
vector<result_type> y(v.size());
std::transform(std::cbegin(v), std::cend(v), std::begin(y), f);
return y;
}
// 多次元vector生成
template <class T> vector<T> make_v(size_t size, const T &init) {
return vector<T>(size, init);
}
template <class... Ts> auto make_v(size_t size, Ts... rest) {
return vector<decltype(make_v(rest...))>(size, make_v(rest...));
}
template <typename T> T Max(vector<T> a) { return *max_element(all(a)); }
template <typename T> T Min(vector<T> a) { return *min_element(all(a)); }
template <typename T> T Sum(vector<T> a) { return accumulate(all(a), (T)0); }
// mapでカウントとかする
template <typename T> void Add(map<T, int> &m, T item) {
if (m.find(item) == m.end()) {
m[item] = 1;
} else {
m[item]++;
}
}
// mapでカウントとかする
template <typename T> void Erase(map<T, int> &m, T item) {
if (m.find(item) == m.end()) {
} else {
if (m[item] == 1) {
m.erase(item);
} else {
m[item]--;
}
}
}
// デフォルト値つきのmapのget
template <typename T, typename U> U Get(map<T, U> m, T key, U def) {
if (m.find(key) == m.end()) {
return def;
} else {
return m[key];
}
}
template <typename T> inline bool Contains(const set<T> &t, const T &key) {
return t.find(key) != t.end();
}
template <typename T, typename U>
inline bool Contains(const map<T, U> &t, const T &key) {
return t.find(key) != t.end();
}
template <class T> struct Edge {
int from, to;
T cost;
bool operator<(Edge e) { return cost < e.cost; }
};
template <class T> ostream &operator<<(ostream &os, Edge<T> &edge) {
os << "(" << edge.from << "->" << edge.to << ":" << edge.cost << ")";
return os;
}
template <class T = int> class Graph {
int n;
bool directed;
vector<vector<Edge<T>>> edges;
public:
Graph(int n, bool directed)
: n(n), directed(directed), edges(vector<vector<Edge<T>>>(n)) {}
void add_edge(int s, int t, T cost) {
edges[s].push_back(Edge<T>{s, t, cost});
if (!directed) {
edges[t].push_back(Edge<T>{t, s, cost});
}
}
Graph() {}
vector<Edge<T>> operator[](size_t i) const { return edges[i]; }
int size() const { return n; }
};
//======================================================
template <class T> class ConvesHullTrick {
static const T IS_QUERY = std::numeric_limits<T>::lowest();
struct Line {
T a, b;
// Lines において次の直線のポインタを得る
mutable std::function<const Line *()> nextLine;
bool operator<(Line rhs) const {
if (b == IS_QUERY) {
// 自分がクエリ
const Line *next_line = rhs.nextLine();
if (next_line == nullptr)
return false;
T x = a;
return (rhs.a - next_line->a) * x + (rhs.b - next_line->b) > 0;
} else if (rhs.b == IS_QUERY) {
// rhs がクエリ
const Line *next_line = nextLine();
if (next_line == nullptr)
return false;
T x = rhs.a;
return (a - next_line->a) * x + (b - next_line->b) > 0;
}
return (a < rhs.a || (a == rhs.a && b < rhs.b));
}
};
set<Line> lines; // 直線集合
bool isVain(Line l) {
dump(l.a, l.b);
// l が不要か判定
auto it = lines.find(l);
auto next_it = next(it);
if (it == lines.begin()) {
if (next_it == lines.end())
return false;
return it->a == next_it->a && it->b <= next_it->b;
} else {
auto prev_it = prev(it);
if (next_it == lines.end())
return it->a == prev_it->a && it->b <= prev_it->b;
return (prev_it->b - it->b) * (it->a - next_it->a) >=
(it->b - next_it->b) * (prev_it->a - it->a);
}
}
public:
void add(T a, T b) {
// 直線 ax+b を追加
auto it = lines.insert(Line{a, b}).first;
// 次の直線を得る関数をセットしておく
it->nextLine = [=] {
return (std::next(it) == lines.end() ? nullptr : &*std::next(it));
};
if (isVain(*it)) {
// 今追加した直線が不要
lines.erase(it);
return;
}
while (next(it) != lines.end() && isVain(*next(it))) {
lines.erase(next(it));
}
while (it != lines.begin() && isVain(*prev(it))) {
lines.erase(prev(it));
}
dump(a, b);
DEB {
for (auto l : lines) {
cerr << l.a << "x+ " << l.b << endl;
}
}
}
T get(T x) {
// x での最小値を出力
auto l = lines.lower_bound(Line{x, IS_QUERY});
dump(x, l->a * x + l->b);
return l->a * x + l->b;
}
};
int main() {
int N;
ll C;
cin >> N >> C;
ConvesHullTrick<ll> CHT;
vll dp(N);
dp[0] = 0;
rep(i, N) {
ll h;
cin >> h;
if (i != 0) {
dp[i] = CHT.get(h) + C + h * h;
dump(i, dp[i]);
}
CHT.add(-2 * h, h * h + dp[i]);
}
cout << dp[N - 1] << endl;
return 0;
}
| [
"variable_declaration.type.change"
] | 987,480 | 987,481 | u366676780 | cpp |
p03185 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf_int = 1e9 + 100;
const ll inf_ll = 5e18;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double dbl;
#define pb push_back
const double pi = 3.1415926535898;
#define dout \
if (debug) \
cout
#define fi first
#define se second
#define sp setprecision
#define sz(a) (int(a.size()))
#define all(a) a.begin(), a.end()
bool debug = 0;
const int MAXN = 1e6 + 100;
const int LOG = 20;
const int mod = 1e9 + 7;
const int MX = 2e7 + 100;
typedef long long li;
const li MOD = 1000000000949747713ll;
struct point {
ll k, b;
point() { k = b = 0; }
point(ll K, ll B) {
k = K;
b = B;
}
};
struct vertex {
point p;
vertex *l, *r;
vertex() { l = r = NULL; }
};
vertex mem[MX];
int top_mem = 0;
inline vertex *get_new(point &cur) {
assert(top_mem < MX);
mem[top_mem].p = cur;
return &mem[top_mem++];
}
ll calc(point &p, ll x) { return p.k * x + p.b; }
vertex *update(vertex *v, int tl, int tr, point cur) {
if (!v)
return get_new(cur);
if (tl == tr) {
if (calc(cur, tl) < calc(v->p, tl)) {
v->p = cur;
}
return v;
} else {
int tm = (tl + tr) >> 1;
if (calc(cur, tm) < calc(v->p, tm)) {
swap(v->p, cur);
}
if (calc(cur, tl) < calc(v->p, tl)) {
v->l = update(v->l, tl, tm, cur);
} else {
v->r = update(v->r, tm + 1, tr, cur);
}
return v;
}
}
ll get(vertex *v, int tl, int tr, int x) {
if (!v)
return inf_ll;
if (tl == tr) {
return calc(v->p, x);
} else {
int tm = (tl + tr) >> 1;
ll cur = calc(v->p, x);
if (tl <= tm) {
return min(cur, get(v->l, tl, tm, x));
} else {
return min(cur, get(v->r, tm + 1, tr, x));
}
}
}
ll h[MAXN];
ll dp[MAXN];
void solve() {
int n;
ll c;
cin >> n >> c;
vertex *root = NULL;
for (int i = 1; i <= n; ++i) {
cin >> h[i];
}
int mx = 2e6;
point p = {-2 * h[1], 1ll * h[1] * h[1]};
root = update(root, 0, mx, p);
for (int i = 2; i <= n; ++i) {
dp[i] = c + h[i] * h[i];
dout << i << " - " << dp[i] << endl;
dp[i] += get(root, 0, mx, h[i]);
point p = {-2 * h[i], dp[i] + h[i] * h[i]};
root = update(root, 0, mx, p);
dout << i << " - " << dp[i] << endl;
}
cout << dp[n];
}
signed main() {
#ifdef zxc
debug = 1;
freopen("../input.txt", "r", stdin);
#else
#endif // zxc
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout.setf(ios::fixed);
cout.precision(20);
int t = 1;
while (t--)
solve();
dout << endl << (1.0 * clock() / CLOCKS_PER_SEC) << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf_int = 1e9 + 100;
const ll inf_ll = 1e18;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double dbl;
#define pb push_back
const double pi = 3.1415926535898;
#define dout \
if (debug) \
cout
#define fi first
#define se second
#define sp setprecision
#define sz(a) (int(a.size()))
#define all(a) a.begin(), a.end()
bool debug = 0;
const int MAXN = 2e5 + 100;
const int LOG = 20;
const int mod = 1e9 + 7;
const int MX = 2e5 + 100;
typedef long long li;
const li MOD = 1000000000949747713ll;
struct point {
ll k, b;
point() { k = b = 0; }
point(ll K, ll B) {
k = K;
b = B;
}
};
struct vertex {
point p;
vertex *l, *r;
vertex() { l = r = NULL; }
};
vertex mem[MX];
int top_mem = 0;
inline vertex *get_new(point &cur) {
assert(top_mem < MX);
mem[top_mem].p = cur;
return &mem[top_mem++];
}
ll calc(point &p, ll x) { return p.k * x + p.b; }
vertex *update(vertex *v, int tl, int tr, point cur) {
if (!v)
return get_new(cur);
if (tl == tr) {
if (calc(cur, tl) < calc(v->p, tl)) {
v->p = cur;
}
return v;
} else {
int tm = (tl + tr) >> 1;
if (calc(cur, tm) < calc(v->p, tm)) {
swap(v->p, cur);
}
if (calc(cur, tl) < calc(v->p, tl)) {
v->l = update(v->l, tl, tm, cur);
} else {
v->r = update(v->r, tm + 1, tr, cur);
}
return v;
}
}
ll get(vertex *v, int tl, int tr, int x) {
if (!v)
return inf_ll;
if (tl == tr) {
return calc(v->p, x);
} else {
int tm = (tl + tr) >> 1;
ll cur = calc(v->p, x);
if (x <= tm) {
return min(cur, get(v->l, tl, tm, x));
} else {
return min(cur, get(v->r, tm + 1, tr, x));
}
}
}
ll h[MAXN];
ll dp[MAXN];
void solve() {
int n;
ll c;
cin >> n >> c;
vertex *root = NULL;
for (int i = 1; i <= n; ++i) {
cin >> h[i];
}
int mx = 2e6;
point p = {-2 * h[1], 1ll * h[1] * h[1]};
root = update(root, 0, mx, p);
for (int i = 2; i <= n; ++i) {
dp[i] = c + h[i] * h[i];
dout << i << " - " << dp[i] << endl;
dp[i] += get(root, 0, mx, h[i]);
point p = {-2 * h[i], dp[i] + h[i] * h[i]};
root = update(root, 0, mx, p);
dout << i << " - " << dp[i] << endl;
}
cout << dp[n];
}
signed main() {
#ifdef zxc
debug = 1;
freopen("../input.txt", "r", stdin);
#else
#endif // zxc
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout.setf(ios::fixed);
cout.precision(20);
int t = 1;
while (t--)
solve();
dout << endl << (1.0 * clock() / CLOCKS_PER_SEC) << endl;
}
| [
"literal.number.change",
"variable_declaration.value.change",
"expression.operation.binary.change",
"identifier.change",
"control_flow.branch.if.condition.change"
] | 987,484 | 987,485 | u813006723 | cpp |
p03185 | #include <bits/stdc++.h>
#define MAXN 1001000
#define lc (x << 1)
#define rc (x << 1 | 1)
#define pii pair<int, int>
#define pb push_back
typedef long long ll;
using namespace std;
ll n, C, h[MAXN], dp[MAXN];
int vis[MAXN << 1];
struct line {
double k, b;
line(double _k = 0, double _b = 0) {
k = _k;
b = _b;
}
double get(double x) { return k * x + b; }
} c[MAXN << 1];
void modify(int x, int l, int r, line v) {
if (!vis[x]) {
vis[x] = 1;
c[x] = v;
return;
}
if (c[x].get(l) > v.get(l) && c[x].get(r) > v.get(r))
return;
if (c[x].get(l) < v.get(l) && c[x].get(r) < v.get(r)) {
c[x] = v;
return;
}
int m = (l + r) >> 1;
if (c[x].get(l) < v.get(l))
swap(c[x], v);
if (c[x].get(m) > v.get(m))
modify(rc, m + 1, r, v);
else {
swap(c[x], v);
modify(lc, l, m, v);
}
}
double get(int x, int l, int r, int pos) {
if (l == r)
return c[x].get(l);
int m = (l + r) >> 1;
double ans = c[x].get(pos);
if (pos <= m)
ans = max(ans, get(lc, l, m, pos));
else
ans = max(ans, get(rc, m + 1, r, pos));
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> C;
for (int i = 0; i < n; i++) {
cin >> h[i];
if (i > 0)
dp[i] = -get(1, 1, 1e6 + 10, h[i]) + h[i] * h[i] + C;
line l = line(2 * h[i], -(dp[i] + h[i] * h[i]));
modify(1, 1, 1e6 + 10, l);
// cout << dp[i] << " ";
}
cout << dp[n - 1];
} | #include <bits/stdc++.h>
#define MAXN 3001000
#define lc (x << 1)
#define rc (x << 1 | 1)
#define pii pair<int, int>
#define pb push_back
typedef long long ll;
using namespace std;
ll n, C, h[MAXN], dp[MAXN];
int vis[MAXN << 1];
struct line {
double k, b;
line(double _k = 0, double _b = 0) {
k = _k;
b = _b;
}
double get(double x) { return k * x + b; }
} c[MAXN << 1];
void modify(int x, int l, int r, line v) {
if (!vis[x]) {
vis[x] = 1;
c[x] = v;
return;
}
if (c[x].get(l) > v.get(l) && c[x].get(r) > v.get(r))
return;
if (c[x].get(l) < v.get(l) && c[x].get(r) < v.get(r)) {
c[x] = v;
return;
}
int m = (l + r) >> 1;
if (c[x].get(l) < v.get(l))
swap(c[x], v);
if (c[x].get(m) > v.get(m))
modify(rc, m + 1, r, v);
else {
swap(c[x], v);
modify(lc, l, m, v);
}
}
double get(int x, int l, int r, int pos) {
if (l == r)
return c[x].get(l);
int m = (l + r) >> 1;
double ans = c[x].get(pos);
if (pos <= m)
ans = max(ans, get(lc, l, m, pos));
else
ans = max(ans, get(rc, m + 1, r, pos));
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> C;
for (int i = 0; i < n; i++) {
cin >> h[i];
if (i > 0)
dp[i] = -get(1, 1, 1e6 + 10, h[i]) + h[i] * h[i] + C;
line l = line(2 * h[i], -(dp[i] + h[i] * h[i]));
modify(1, 1, 1e6 + 10, l);
// cout << dp[i] << " ";
}
cout << dp[n - 1];
} | [
"preprocessor.define.value.change",
"literal.integer.change"
] | 987,529 | 987,528 | u190314045 | cpp |
p03185 | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define N 200005
ll inf = 1e14;
ll mod = 1e9 + 7;
char en = '\n';
ll abs1(ll x) {
if (x < 0)
return -x;
return x;
}
ll power(ll x, ll n, ll mod) {
ll res = 1;
while (n) {
if (n & 1)
res = (res * x) % mod;
x = (x * x) % mod;
n >>= 1;
}
return res;
}
// Convex hull,maximum
bool Q;
struct Line {
mutable ll k, m, p;
bool operator<(const Line &o) const { return Q ? p < o.p : k < o.k; }
};
struct LineContainer : multiset<Line> {
ll div(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); }
bool isect(iterator x, iterator y) {
if (y == end()) {
x->p = inf;
return false;
}
if (x->k == y->k)
x->p = x->m > y->m ? inf : -inf;
else
x->p = div(y->m - x->m, x->k - y->k);
return x->p >= y->p;
}
void add(ll k, ll m) {
auto z = insert({k, m, 0}), y = z++, x = y;
while (isect(y, z))
z = erase(z);
if (x != begin() && isect(--x, y))
isect(x, y = erase(y));
while ((y = x) != begin() && (--x)->p >= y->p)
isect(x, erase(y));
}
ll query(ll x) {
// cout<<endl<<jk<<endl;
assert(!empty());
Q = 1;
auto l = *lower_bound({0, 0, x});
Q = 0;
// cout<<l.k<<" h "<<l.m<<endl;
return l.k * x + l.m;
}
};
LineContainer obj;
// usage if want minimum,then if y=mx+c ,convert it to equation y'=-mx-c,and
// then do the below,only at last res=-obj.query(xi) adding line
// y=mx+c->obj.add(m,c) querying-> obj.query(x)
// sample problem: https://www.codechef.com/JULY18A/problems/PDELIV/
// sample solution: https://www.codechef.com/viewsolution/19132562
ld dp[N];
ld arr[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n, c;
cin >> n >> c;
for (ll i = 1; i <= n; i++)
cin >> arr[i];
memset(dp, 0, sizeof(dp));
obj.add(2 * arr[1], -arr[1] * arr[1] - dp[1]);
for (ll i = 2; i <= n; i++) {
dp[i] = -obj.query(arr[i]) + arr[i] * arr[i] + c;
obj.add(2 * arr[i], -arr[i] * arr[i] - dp[i]);
}
cout << dp[n] << en;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define N 200005
ll inf = 1e14;
ll mod = 1e9 + 7;
char en = '\n';
ll abs1(ll x) {
if (x < 0)
return -x;
return x;
}
ll power(ll x, ll n, ll mod) {
ll res = 1;
while (n) {
if (n & 1)
res = (res * x) % mod;
x = (x * x) % mod;
n >>= 1;
}
return res;
}
// Convex hull,maximum
bool Q;
struct Line {
mutable ll k, m, p;
bool operator<(const Line &o) const { return Q ? p < o.p : k < o.k; }
};
struct LineContainer : multiset<Line> {
ll div(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); }
bool isect(iterator x, iterator y) {
if (y == end()) {
x->p = inf;
return false;
}
if (x->k == y->k)
x->p = x->m > y->m ? inf : -inf;
else
x->p = div(y->m - x->m, x->k - y->k);
return x->p >= y->p;
}
void add(ll k, ll m) {
auto z = insert({k, m, 0}), y = z++, x = y;
while (isect(y, z))
z = erase(z);
if (x != begin() && isect(--x, y))
isect(x, y = erase(y));
while ((y = x) != begin() && (--x)->p >= y->p)
isect(x, erase(y));
}
ll query(ll x) {
// cout<<endl<<jk<<endl;
assert(!empty());
Q = 1;
auto l = *lower_bound({0, 0, x});
Q = 0;
// cout<<l.k<<" h "<<l.m<<endl;
return l.k * x + l.m;
}
};
LineContainer obj;
// usage if want minimum,then if y=mx+c ,convert it to equation y'=-mx-c,and
// then do the below,only at last res=-obj.query(xi) adding line
// y=mx+c->obj.add(m,c) querying-> obj.query(x)
// sample problem: https://www.codechef.com/JULY18A/problems/PDELIV/
// sample solution: https://www.codechef.com/viewsolution/19132562
ll dp[N];
ll arr[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n, c;
cin >> n >> c;
for (ll i = 1; i <= n; i++)
cin >> arr[i];
memset(dp, 0, sizeof(dp));
obj.add(2 * arr[1], -arr[1] * arr[1] - dp[1]);
for (ll i = 2; i <= n; i++) {
dp[i] = -obj.query(arr[i]) + arr[i] * arr[i] + c;
obj.add(2 * arr[i], -arr[i] * arr[i] - dp[i]);
}
cout << dp[n] << en;
return 0;
}
| [
"variable_declaration.type.change"
] | 987,530 | 987,531 | u401416019 | cpp |
p03185 | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define N 3005
ll inf = 1e14;
ll mod = 1e9 + 7;
char en = '\n';
ll abs1(ll x) {
if (x < 0)
return -x;
return x;
}
ll power(ll x, ll n, ll mod) {
ll res = 1;
while (n) {
if (n & 1)
res = (res * x) % mod;
x = (x * x) % mod;
n >>= 1;
}
return res;
}
// Convex hull,maximum
bool Q;
struct Line {
mutable ll k, m, p;
bool operator<(const Line &o) const { return Q ? p < o.p : k < o.k; }
};
struct LineContainer : multiset<Line> {
ll div(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); }
bool isect(iterator x, iterator y) {
if (y == end()) {
x->p = inf;
return false;
}
if (x->k == y->k)
x->p = x->m > y->m ? inf : -inf;
else
x->p = div(y->m - x->m, x->k - y->k);
return x->p >= y->p;
}
void add(ll k, ll m) {
auto z = insert({k, m, 0}), y = z++, x = y;
while (isect(y, z))
z = erase(z);
if (x != begin() && isect(--x, y))
isect(x, y = erase(y));
while ((y = x) != begin() && (--x)->p >= y->p)
isect(x, erase(y));
}
ll query(ll x) {
// cout<<endl<<jk<<endl;
assert(!empty());
Q = 1;
auto l = *lower_bound({0, 0, x});
Q = 0;
// cout<<l.k<<" h "<<l.m<<endl;
return l.k * x + l.m;
}
};
LineContainer obj;
// usage if want minimum,then if y=mx+c ,convert it to equation y'=-mx-c,and
// then do the below,only at last res=-obj.query(xi) adding line
// y=mx+c->obj.add(m,c) querying-> obj.query(x)
// sample problem: https://www.codechef.com/JULY18A/problems/PDELIV/
// sample solution: https://www.codechef.com/viewsolution/19132562
ld dp[N];
ld arr[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n, c;
cin >> n >> c;
for (ll i = 1; i <= n; i++)
cin >> arr[i];
memset(dp, 0, sizeof(dp));
obj.add(2 * arr[1], -arr[1] * arr[1] - dp[1]);
for (ll i = 2; i <= n; i++) {
dp[i] = -obj.query(arr[i]) + arr[i] * arr[i] + c;
obj.add(2 * arr[i], -arr[i] * arr[i] - dp[i]);
}
cout << dp[n] << en;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define N 200005
ll inf = 1e14;
ll mod = 1e9 + 7;
char en = '\n';
ll abs1(ll x) {
if (x < 0)
return -x;
return x;
}
ll power(ll x, ll n, ll mod) {
ll res = 1;
while (n) {
if (n & 1)
res = (res * x) % mod;
x = (x * x) % mod;
n >>= 1;
}
return res;
}
// Convex hull,maximum
bool Q;
struct Line {
mutable ll k, m, p;
bool operator<(const Line &o) const { return Q ? p < o.p : k < o.k; }
};
struct LineContainer : multiset<Line> {
ll div(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); }
bool isect(iterator x, iterator y) {
if (y == end()) {
x->p = inf;
return false;
}
if (x->k == y->k)
x->p = x->m > y->m ? inf : -inf;
else
x->p = div(y->m - x->m, x->k - y->k);
return x->p >= y->p;
}
void add(ll k, ll m) {
auto z = insert({k, m, 0}), y = z++, x = y;
while (isect(y, z))
z = erase(z);
if (x != begin() && isect(--x, y))
isect(x, y = erase(y));
while ((y = x) != begin() && (--x)->p >= y->p)
isect(x, erase(y));
}
ll query(ll x) {
// cout<<endl<<jk<<endl;
assert(!empty());
Q = 1;
auto l = *lower_bound({0, 0, x});
Q = 0;
// cout<<l.k<<" h "<<l.m<<endl;
return l.k * x + l.m;
}
};
LineContainer obj;
// usage if want minimum,then if y=mx+c ,convert it to equation y'=-mx-c,and
// then do the below,only at last res=-obj.query(xi) adding line
// y=mx+c->obj.add(m,c) querying-> obj.query(x)
// sample problem: https://www.codechef.com/JULY18A/problems/PDELIV/
// sample solution: https://www.codechef.com/viewsolution/19132562
ll dp[N];
ll arr[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n, c;
cin >> n >> c;
for (ll i = 1; i <= n; i++)
cin >> arr[i];
memset(dp, 0, sizeof(dp));
obj.add(2 * arr[1], -arr[1] * arr[1] - dp[1]);
for (ll i = 2; i <= n; i++) {
dp[i] = -obj.query(arr[i]) + arr[i] * arr[i] + c;
obj.add(2 * arr[i], -arr[i] * arr[i] - dp[i]);
}
cout << dp[n] << en;
return 0;
}
| [
"preprocessor.define.value.change",
"literal.integer.change",
"variable_declaration.type.change"
] | 987,532 | 987,531 | u401416019 | cpp |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.