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 |
|---|---|---|---|---|---|---|---|
p03091 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)
class UnionFind {
private:
vector<int> p, r;
public:
int comp;
UnionFind(int n) {
r.assign(n, 0);
p.resize(n);
iota(ALL(p), 0);
comp = n;
}
int findset(int i) { return (p[i] == i) ? i : (p[i] = findset(p[i])); }
bool unionset(int i, int j) {
int x = findset(i), y = findset(j);
if (x != y) {
--comp;
if (r[x] > r[y])
p[y] = x;
else {
p[x] = y;
if (r[x] == r[y])
++r[y];
}
return true;
}
return false;
}
};
int main() {
// freopen("in.txt", "r", stdin);
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
int deg[n];
memset(deg, 0, sizeof deg);
vector<ii> el;
FOR(i, 0, m - 1) {
int a, b;
cin >> a >> b;
--a, --b;
++deg[a], ++deg[b];
el.emplace_back(a, b);
}
string ans = "";
int deg4 = 0, x = -1;
FOR(i, 0, n - 1) {
if (deg[i] % 2 == 1) {
ans = "No";
break;
}
if (deg[i] >= 6) {
ans = "Yes";
break;
}
if (deg[i] == 4)
++deg4, x = i;
}
if (ans == "") {
if (deg4 >= 3)
ans = "Yes";
else if (deg4 == 2) {
UnionFind UF(n);
for (auto e : el) {
if (e.fi != x and e.sc != x)
UF.unionset(e.fi, e.sc);
}
if (UF.comp >= 3)
ans = "Yes";
else
ans = "No";
} else
ans = "No";
}
cout << ans << '\n';
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)
class UnionFind {
private:
vector<int> p, r;
public:
int comp;
UnionFind(int n) {
r.assign(n, 0);
p.resize(n);
iota(ALL(p), 0);
comp = n;
}
int findset(int i) { return (p[i] == i) ? i : (p[i] = findset(p[i])); }
bool unionset(int i, int j) {
int x = findset(i), y = findset(j);
if (x != y) {
--comp;
if (r[x] > r[y])
p[y] = x;
else {
p[x] = y;
if (r[x] == r[y])
++r[y];
}
return true;
}
return false;
}
};
int main() {
// freopen("in.txt", "r", stdin);
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
int deg[n];
memset(deg, 0, sizeof deg);
vector<ii> el;
FOR(i, 0, m - 1) {
int a, b;
cin >> a >> b;
--a, --b;
++deg[a], ++deg[b];
el.emplace_back(a, b);
}
string ans = "";
int deg4 = 0, x = -1;
FOR(i, 0, n - 1) {
if (deg[i] % 2 == 1) {
ans = "No";
break;
}
if (deg[i] >= 6)
ans = "Yes";
if (deg[i] == 4)
++deg4, x = i;
}
if (ans == "") {
if (deg4 >= 3)
ans = "Yes";
else if (deg4 == 2) {
UnionFind UF(n);
for (auto e : el) {
if (e.fi != x and e.sc != x)
UF.unionset(e.fi, e.sc);
}
if (UF.comp >= 3)
ans = "Yes";
else
ans = "No";
} else
ans = "No";
}
cout << ans << '\n';
}
| [] | 906,537 | 906,538 | u120305309 | cpp |
p03095 | #include <iostream>
#include <string>
#define MOD 1000000007
using namespace std;
long long ans;
int cnt[30], n;
string s;
void dfs(int here, long long ansHere) {
if (here == 'z' - 'a') {
ans = (ans + ansHere) % MOD;
return;
}
dfs(here + 1, ansHere);
if (cnt[here] > 0)
dfs(here + 1, (ansHere * cnt[here]) % MOD);
}
int main() {
cin.tie(NULL);
ios::sync_with_stdio(false);
cin >> n >> s;
for (int i = 0; i < n; i++)
cnt[s[i] - 'a']++;
dfs(0, 1);
cout << ans - 1 << '\n';
} | #include <iostream>
#include <string>
#define MOD 1000000007
using namespace std;
long long ans;
int cnt[30], n;
string s;
void dfs(int here, long long ansHere) {
if (here == 'z' - 'a' + 1) {
ans = (ans + ansHere) % MOD;
return;
}
dfs(here + 1, ansHere);
if (cnt[here] > 0)
dfs(here + 1, (ansHere * cnt[here]) % MOD);
}
int main() {
cin.tie(NULL);
ios::sync_with_stdio(false);
cin >> n >> s;
for (int i = 0; i < n; i++)
cnt[s[i] - 'a']++;
dfs(0, 1);
cout << ans - 1 << '\n';
} | [
"control_flow.branch.if.condition.change"
] | 906,543 | 906,544 | u894126219 | cpp |
p03095 | #include <iostream>
#include <string>
#define MOD 1000000007
using namespace std;
long long ans;
int cnt[30], n;
string s;
void dfs(int here, int ansHere) {
if (here == 'z' - 'a') {
ans = (ans + ansHere) % MOD;
return;
}
dfs(here + 1, ansHere);
if (cnt[here] > 0)
dfs(here + 1, (ansHere * cnt[here]) % MOD);
}
int main() {
cin.tie(NULL);
ios::sync_with_stdio(false);
cin >> n >> s;
for (int i = 0; i < n; i++)
cnt[s[i] - 'a']++;
dfs(0, 1);
cout << ans - 1 << '\n';
} | #include <iostream>
#include <string>
#define MOD 1000000007
using namespace std;
long long ans;
int cnt[30], n;
string s;
void dfs(int here, long long ansHere) {
if (here == 'z' - 'a' + 1) {
ans = (ans + ansHere) % MOD;
return;
}
dfs(here + 1, ansHere);
if (cnt[here] > 0)
dfs(here + 1, (ansHere * cnt[here]) % MOD);
}
int main() {
cin.tie(NULL);
ios::sync_with_stdio(false);
cin >> n >> s;
for (int i = 0; i < n; i++)
cnt[s[i] - 'a']++;
dfs(0, 1);
cout << ans - 1 << '\n';
} | [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change",
"control_flow.branch.if.condition.change"
] | 906,545 | 906,544 | u894126219 | cpp |
p03095 | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
typedef long long ll;
using namespace std;
int n;
string s;
long long int a[26] = {0};
int main() {
cin >> n;
cin >> s;
long long int ans = 0;
for (int i = 0; i < n; i++) {
a[s[i] - 'a']++;
}
for (int i = 0; i < n; i++) {
if (a[i] != 0) {
if (ans == 0) {
ans = a[i] + 1;
} else {
ans = (ans * (a[i] + 1)) % 1000000009;
}
}
}
cout << ans - 1;
return 0;
} | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
typedef long long ll;
using namespace std;
int n;
string s;
long long int a[26] = {0};
int main() {
cin >> n;
cin >> s;
long long int ans = 0;
for (int i = 0; i < n; i++) {
a[s[i] - 'a']++;
}
for (int i = 0; i < 26; i++) {
if (a[i] != 0) {
if (ans == 0) {
ans = a[i] + 1;
} else {
ans = (ans * (a[i] + 1)) % 1000000007;
}
}
}
cout << ans - 1;
return 0;
} | [
"identifier.replace.remove",
"literal.replace.add",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change",
"literal.number.change",
"assignment.value.change"
] | 906,562 | 906,561 | u629194491 | cpp |
p03095 | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
typedef long long ll;
using namespace std;
int n;
string s;
int a[26] = {0};
int main() {
cin >> n;
cin >> s;
int ans = 0;
for (int i = 0; i < n; i++) {
a[s[i] - 'a']++;
}
for (int i = 0; i < n; i++) {
if (a[i] != 0) {
if (ans == 0) {
ans = a[i] + 1;
} else {
ans = (ans * (a[i] + 1)) % 1000000009;
}
}
}
cout << ans - 1;
return 0;
} | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
typedef long long ll;
using namespace std;
int n;
string s;
long long int a[26] = {0};
int main() {
cin >> n;
cin >> s;
long long int ans = 0;
for (int i = 0; i < n; i++) {
a[s[i] - 'a']++;
}
for (int i = 0; i < 26; i++) {
if (a[i] != 0) {
if (ans == 0) {
ans = a[i] + 1;
} else {
ans = (ans * (a[i] + 1)) % 1000000007;
}
}
}
cout << ans - 1;
return 0;
} | [
"identifier.replace.remove",
"literal.replace.add",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change",
"literal.number.change",
"assignment.value.change"
] | 906,563 | 906,561 | u629194491 | cpp |
p03095 | /*{{{*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return
// a[0]<b[0];});
#define REP(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define RREP(i, n) for (ll(i) = (n)-1; (i) >= 0; (i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a, b) a = max((a), (b))
#define CHMIN(a, b) a = min((a), (b))
/*}}}*/
int main() {
ll n;
ll MOD = 1000000000 + 7;
string s;
cin >> n;
cin >> s;
ll abc[30];
REP(i, 30) abc[i] = 1;
ll ans = 1;
REP(i, n) { abc[s[i] - 'a']++; }
REP(i, (ll)('z' - 'a')) {
ans *= abc[i];
ans %= MOD;
}
ans -= 1;
cout << ans << endl;
return 0;
}
| /*{{{*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return
// a[0]<b[0];});
#define REP(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define RREP(i, n) for (ll(i) = (n)-1; (i) >= 0; (i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a, b) a = max((a), (b))
#define CHMIN(a, b) a = min((a), (b))
/*}}}*/
int main() {
ll n;
ll MOD = 1000000000 + 7;
string s;
cin >> n;
cin >> s;
ll abc[30];
REP(i, 30) abc[i] = 1;
ll ans = 1;
REP(i, n) { abc[s[i] - 'a']++; }
REP(i, (ll)('z' - 'a' + 1)) {
ans *= abc[i];
ans %= MOD;
}
ans -= 1;
cout << ans << endl;
return 0;
}
| [
"expression.operation.binary.add"
] | 906,572 | 906,573 | u088893297 | cpp |
p03095 | #include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
const int mod = 1e9 + 7;
int sum[30], Ans;
char s[100100];
int main() {
int n, m, i, j, k;
cin >> n;
scanf("%d", s);
for (i = 0; i < n; i++)
sum[s[i] - 'a']++;
for (i = 0; i < 26; i++)
Ans = 1ll * Ans * (sum[i] + 1) % mod;
cout << Ans - 1 << endl;
return 0;
}
| #include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
const int mod = 1e9 + 7;
int sum[30], Ans = 1;
char s[100100];
int main() {
int n, m, i, j, k;
cin >> n;
scanf("%s", s);
for (i = 0; i < n; i++)
sum[s[i] - 'a']++;
for (i = 0; i < 26; i++)
Ans = 1ll * Ans * (sum[i] + 1) % mod;
cout << Ans - 1 << endl;
return 0;
}
| [
"variable_declaration.value.change",
"literal.string.change",
"call.arguments.change"
] | 906,609 | 906,610 | u964391729 | cpp |
p03095 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const int dx[4] = {+1, 0, -1, 0};
const int dy[4] = {0, -1, 0, +1};
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
ll n;
cin >> n;
string str;
cin >> str;
ll cnt[26];
for (int i = 0; i < 26; i++)
cnt[i] = 0;
for (int i = 0; i < n; i++) {
cnt[str[i] - 'a']++;
}
ll ans = 1;
for (int i = 0; i < n; i++) {
ans = (ans * (cnt[i] + 1)) % MOD;
}
cout << ans - 1 << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const int dx[4] = {+1, 0, -1, 0};
const int dy[4] = {0, -1, 0, +1};
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
ll n;
cin >> n;
string str;
cin >> str;
ll cnt[26];
for (int i = 0; i < 26; i++)
cnt[i] = 0;
for (int i = 0; i < n; i++) {
cnt[str[i] - 'a']++;
}
ll ans = 1;
for (int i = 0; i < 26; i++) {
ans = (ans * (cnt[i] + 1)) % MOD;
}
cout << ans - 1 << endl;
} | [
"identifier.replace.remove",
"literal.replace.add",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 906,615 | 906,616 | u637771514 | cpp |
p03095 | #include <bits/stdc++.h>
using namespace std;
#define forw(i, a, n) for (int i = a; i < n; i++)
#define ford(i, a, n) for (int i = n - 1; i >= a; i--)
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
const ll mod = 1000000007;
const int maxn = 1e5 + 3;
void mf() {
freopen("input.in", "r", stdin);
// freopen("output.ou","w",stdout);
}
// START SOL
int c[30];
int n;
string st;
void solve() {
cin >> n;
for (int i = 0; i <= 26; i++)
c[i] = 0;
cin >> st;
for (int i = 0; i < n; i++) {
c[st[i] - 'a' + 1]++;
}
ll s = 1;
for (int i = 0; i < 26; i++) {
if (c[i] == 0)
continue;
s = (s * (c[i] + 1)) % mod;
}
s -= 1;
if (s < 0)
s = (s + mod) % mod;
cout << s;
}
int main() {
ios_base::sync_with_stdio(false);
#ifdef tuanh
mf();
#endif
solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define forw(i, a, n) for (int i = a; i < n; i++)
#define ford(i, a, n) for (int i = n - 1; i >= a; i--)
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
const ll mod = 1000000007;
const int maxn = 1e5 + 3;
void mf() {
freopen("input.in", "r", stdin);
// freopen("output.ou","w",stdout);
}
// START SOL
int c[30];
int n;
string st;
void solve() {
cin >> n;
for (int i = 0; i <= 26; i++)
c[i] = 0;
cin >> st;
for (int i = 0; i < n; i++) {
c[st[i] - 'a' + 1]++;
}
ll s = 1;
for (int i = 1; i <= 26; i++) {
if (c[i] == 0)
continue;
s = (s * (c[i] + 1)) % mod;
}
s -= 1;
if (s < 0)
s = (s + mod) % mod;
cout << s;
}
int main() {
ios_base::sync_with_stdio(false);
#ifdef tuanh
mf();
#endif
solve();
return 0;
} | [
"literal.number.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one",
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 906,619 | 906,620 | u600000692 | cpp |
p03095 | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
string S;
int count[26] = {};
cin >> N;
cin >> S;
for (int i = 0; i < N; i++) {
count[S[i] - 'a']++;
}
int ans = 1;
for (int i = 0; i < N; i++) {
ans *= count[i] + 1;
ans %= 1000000007;
}
cout << ans - 1 << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
string S;
int count[26] = {};
cin >> N;
cin >> S;
for (int i = 0; i < N; i++) {
count[S[i] - 'a']++;
}
long long int ans = 1;
for (int i = 0; i < 26; i++) {
ans *= count[i] + 1;
ans %= 1000000007;
}
cout << ans - 1 << endl;
return 0;
} | [
"identifier.replace.remove",
"literal.replace.add",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 906,647 | 906,646 | u506320030 | cpp |
p03095 | #include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
#define F first
#define S second
int n;
string s;
int a[28];
unordered_set<int> st;
signed main() {
cin >> n;
cin >> s;
r(i, n) { a[s[i] - 'a']++; }
int ans = 1, S = 0, sum = 0;
r(i, 26) if (a[i]) S++;
r(i, 26) {
if (a[i]) {
int x = a[i];
r(j, n) if (i < j && a[j]) {
x *= (a[j] + 1);
x %= 1000000007;
}
x %= 1000000007;
ans += x;
ans %= 1000000007;
S--;
}
}
/*r(i,(1<<26)){
int A=0,p=1;
r(j,26){
if(i&(1<<j)){
A|=(1<<j);
p*=a[j];
p%=1000000007;
}
}
if(!st.count(A)&&p){
//cout<<A<<endl;
st.insert(A);
ans+=p;
ans%=1000000007;
}
}*/
cout << ans - 1 << endl;
} | #include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
#define F first
#define S second
int n;
string s;
int a[28];
unordered_set<int> st;
signed main() {
cin >> n;
cin >> s;
r(i, n) { a[s[i] - 'a']++; }
int ans = 1, S = 0, sum = 0;
r(i, 26) if (a[i]) S++;
r(i, 26) {
if (a[i]) {
int x = a[i];
r(j, 26) if (i < j && a[j]) {
x *= (a[j] + 1);
x %= 1000000007;
}
x %= 1000000007;
ans += x;
ans %= 1000000007;
S--;
}
}
/*r(i,(1<<26)){
int A=0,p=1;
r(j,26){
if(i&(1<<j)){
A|=(1<<j);
p*=a[j];
p%=1000000007;
}
}
if(!st.count(A)&&p){
//cout<<A<<endl;
st.insert(A);
ans+=p;
ans%=1000000007;
}
}*/
cout << ans - 1 << endl;
} | [
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change"
] | 906,648 | 906,649 | u777468981 | cpp |
p03095 | /*
* @Author: wxyww
* @Date: 2019-03-16 20:09:11
* @Last Modified time: 2019-03-16 20:12:01
*/
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
ll read() {
ll x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
return x * f;
}
const int N = 30;
int a[N];
int ans;
int n;
const int mod = 1e9 + 7;
void dfs(int now, int ret) {
if (now == n + 1) {
ans += ret;
ans %= mod;
return;
}
dfs(now + 1, ret);
if (a[now])
dfs(now + 1, 1ll * ret * a[now] % mod);
}
char s[100004];
int main() {
n = read();
scanf("%s", s + 1);
for (int i = 1; i <= n; ++i)
a[s[i] - 'a' + 1]++;
dfs(1, 1);
cout << ans - 1;
return 0;
} | /*
* @Author: wxyww
* @Date: 2019-03-16 20:09:11
* @Last Modified time: 2019-03-16 20:13:41
*/
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
ll read() {
ll x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
return x * f;
}
const int N = 30;
int a[N];
int ans;
int n;
const int mod = 1e9 + 7;
void dfs(int now, int ret) {
if (now == 27) {
ans += ret;
ans %= mod;
return;
}
dfs(now + 1, ret);
if (a[now])
dfs(now + 1, 1ll * ret * a[now] % mod);
}
char s[100004];
int main() {
n = read();
scanf("%s", s + 1);
for (int i = 1; i <= n; ++i)
a[s[i] - 'a' + 1]++;
dfs(1, 1);
cout << ans - 1;
return 0;
} | [
"identifier.replace.remove",
"literal.replace.add",
"control_flow.branch.if.condition.change",
"expression.operation.binary.remove"
] | 906,650 | 906,651 | u541541158 | cpp |
p03095 | #include <algorithm>
#include <cctype>
#include <cstdio>
namespace fast_IO {
const int IN_LEN = 1000000, OUT_LEN = 1000000;
char ibuf[IN_LEN], obuf[OUT_LEN], *ih = ibuf + IN_LEN, *oh = obuf,
*lastin = ibuf + IN_LEN,
*lastout = obuf + OUT_LEN - 1;
inline char getchar_() {
return (ih == lastin) &&
(lastin = (ih = ibuf) + fread(ibuf, 1, IN_LEN, stdin),
ih == lastin)
? EOF
: *ih++;
}
inline void putchar_(const char x) {
if (oh == lastout)
fwrite(obuf, 1, oh - obuf, stdout), oh = obuf;
*oh++ = x;
}
inline void flush() { fwrite(obuf, 1, oh - obuf, stdout); }
} // namespace fast_IO
using namespace fast_IO;
//#define getchar() getchar_()
//#define putchar(x) putchar_((x))
//#include<ctime>
#define rg register
typedef long long ll;
template <typename T> inline T max(const T a, const T b) {
return a > b ? a : b;
}
template <typename T> inline T min(const T a, const T b) {
return a < b ? a : b;
}
template <typename T> inline void mind(T &a, const T b) { a = a < b ? a : b; }
template <typename T> inline void maxd(T &a, const T b) { a = a > b ? a : b; }
template <typename T> inline T abs(const T a) { return a > 0 ? a : -a; }
template <typename T> inline void swap(T &a, T &b) {
T c = a;
a = b;
b = c;
}
// template <typename T> inline void swap(T*a,T*b){T c=a;a=b;b=c;}
template <typename T> inline T gcd(const T a, const T b) {
if (!b)
return a;
return gcd(b, a % b);
}
template <typename T> inline T lcm(const T a, const T b) {
return a / gcd(a, b) * b;
}
template <typename T> inline T square(const T x) { return x * x; };
template <typename T> inline void read(T &x) {
char cu = getchar();
x = 0;
bool fla = 0;
while (!isdigit(cu)) {
if (cu == '-')
fla = 1;
cu = getchar();
}
while (isdigit(cu))
x = x * 10 + cu - '0', cu = getchar();
if (fla)
x = -x;
}
template <typename T> inline void printe(const T x) {
if (x >= 10)
printe(x / 10);
putchar(x % 10 + '0');
}
template <typename T> inline void print(const T x) {
if (x < 0)
putchar('-'), printe(-x);
else
printe(x);
}
const int mod = 1000000007;
int n;
char s[100001];
int tot[26];
ll ans = 1;
int main() {
scanf("%d %s", &n, s + 1);
for (rg int i = 1; i <= n; i++)
tot[s[i] - 'a']++;
for (rg int i = 0; i < 26; i++)
ans = ans * (tot[i] + 1) % mod;
print(ans);
return flush(), 0;
} | #include <algorithm>
#include <cctype>
#include <cstdio>
namespace fast_IO {
const int IN_LEN = 1000000, OUT_LEN = 1000000;
char ibuf[IN_LEN], obuf[OUT_LEN], *ih = ibuf + IN_LEN, *oh = obuf,
*lastin = ibuf + IN_LEN,
*lastout = obuf + OUT_LEN - 1;
inline char getchar_() {
return (ih == lastin) &&
(lastin = (ih = ibuf) + fread(ibuf, 1, IN_LEN, stdin),
ih == lastin)
? EOF
: *ih++;
}
inline void putchar_(const char x) {
if (oh == lastout)
fwrite(obuf, 1, oh - obuf, stdout), oh = obuf;
*oh++ = x;
}
inline void flush() { fwrite(obuf, 1, oh - obuf, stdout); }
} // namespace fast_IO
using namespace fast_IO;
//#define getchar() getchar_()
//#define putchar(x) putchar_((x))
//#include<ctime>
#define rg register
typedef long long ll;
template <typename T> inline T max(const T a, const T b) {
return a > b ? a : b;
}
template <typename T> inline T min(const T a, const T b) {
return a < b ? a : b;
}
template <typename T> inline void mind(T &a, const T b) { a = a < b ? a : b; }
template <typename T> inline void maxd(T &a, const T b) { a = a > b ? a : b; }
template <typename T> inline T abs(const T a) { return a > 0 ? a : -a; }
template <typename T> inline void swap(T &a, T &b) {
T c = a;
a = b;
b = c;
}
// template <typename T> inline void swap(T*a,T*b){T c=a;a=b;b=c;}
template <typename T> inline T gcd(const T a, const T b) {
if (!b)
return a;
return gcd(b, a % b);
}
template <typename T> inline T lcm(const T a, const T b) {
return a / gcd(a, b) * b;
}
template <typename T> inline T square(const T x) { return x * x; };
template <typename T> inline void read(T &x) {
char cu = getchar();
x = 0;
bool fla = 0;
while (!isdigit(cu)) {
if (cu == '-')
fla = 1;
cu = getchar();
}
while (isdigit(cu))
x = x * 10 + cu - '0', cu = getchar();
if (fla)
x = -x;
}
template <typename T> inline void printe(const T x) {
if (x >= 10)
printe(x / 10);
putchar(x % 10 + '0');
}
template <typename T> inline void print(const T x) {
if (x < 0)
putchar('-'), printe(-x);
else
printe(x);
}
const int mod = 1000000007;
int n;
char s[100001];
int tot[26];
ll ans = 1;
int main() {
scanf("%d %s", &n, s + 1);
for (rg int i = 1; i <= n; i++)
tot[s[i] - 'a']++;
for (rg int i = 0; i < 26; i++)
ans = ans * (tot[i] + 1) % mod;
print(ans - 1);
return flush(), 0;
} | [
"expression.operation.binary.add"
] | 906,652 | 906,653 | u303645731 | cpp |
p03095 | #include <algorithm>
#include <array>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>
#define rep(i, s, n) for (int i = (s); (n) > i; i++)
#define REP(i, n) rep(i, 0, n)
#define RANGE(x, a, b) ((a) <= (x) && (x) < (b))
#define DUPLE(a, b, c, d) \
(RANGE(a, c, d) || RANGE(b, c, d) || RANGE(c, a, b) || RANGE(d, a, b))
#define INCLU(a, b, c, d) (RANGE(a, c, d) && (b, c, d))
#define PW(x) ((x) * (x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007LL
#define bitcheck(a, b) ((a >> b) & 1)
#define bitset(a, b) (a |= (1 << b))
#define bitunset(a, b) (a &= ~(1 << b))
#define MP(a, b) make_pair((a), (b))
#define Manh(a, b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589
#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
std::fill((T *)array, (T *)(array + N), val);
}
pll Dir[8] = { //移動
{0, 1}, {-1, 0}, {1, 0}, {0, -1}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
//[a, b)
#define Getsum(ar, a, b) (ar[b] - ar[a])
#define INF 10000000000000000LL
struct Edge {
ll from, to;
ll w;
};
typedef vector<vector<Edge>> Graph;
template <typename T> // Tのデフォルトコンストラクタが単位元となる
class ScapegoatTree_Leaf {
public:
struct Node {
int range[2]; // [range[0], range[1])
T val;
Node *p = NULL, *l = NULL, *r = NULL;
bool removed = false, leaf;
int sz = 1, dc = 0, coin = 0;
Node(Node *par, int rangel, int ranger, Node *left, Node *right)
: leaf(false), val(T()), p(par), l(left), r(right) {
range[0] = rangel, range[1] = ranger;
}
Node(Node *par, int t, T _val) : leaf(true), val(_val), p(par) {
range[0] = t, range[1] = t + 1;
}
void upd() {
if (!leaf) {
sz = 1 + l->sz + r->sz;
dc = removed + l->dc + r->dc;
range[0] = l->range[0];
range[1] = r->range[1];
val = l->val + r->val;
} else {
dc = removed;
}
}
int size() { return sz - dc; }
};
#define MAXPOOLSIZE 3000000
mt19937 engine;
Node *root = NULL;
int poolcou = 0;
Node *nodepool[MAXPOOLSIZE] = {};
void updpath(Node *node) {
Node *cur = node;
while (cur != NULL) {
cur->upd();
cur = cur->p;
}
}
int depth(Node *node) {
Node *cur = node;
int c = 0;
while (cur != root) {
cur = cur->p;
c++;
}
return c;
}
void DeleteNode(Node *node) {
nodepool[poolcou] = node;
poolcou++;
}
Node *NewNode(Node *par, int rangel, int ranger, Node *left, Node *right) {
Node *ret;
if (poolcou) {
ret = nodepool[poolcou - 1], poolcou--;
ret->removed = false, ret->sz = 1, ret->dc = 0, ret->val = T(),
ret->leaf = false, ret->p = par, ret->range[0] = rangel,
ret->range[1] = ranger, ret->l = left, ret->r = right;
} else
ret = new Node(par, rangel, ranger, left, right);
return ret;
}
Node *NewNode(Node *par, int t, T _val) {
Node *ret;
if (poolcou) {
ret = nodepool[poolcou - 1], poolcou--;
ret->removed = false, ret->sz = 1, ret->dc = 0, ret->leaf = true,
ret->p = par, ret->range[0] = t, ret->range[1] = t + 1, ret->val = _val;
} else
ret = new Node(par, t, _val);
return ret;
}
void getarray(vector<Node *> &ar, Node *node, bool rem) {
if (node->leaf) {
if (node->removed && rem)
DeleteNode(node);
else
ar.push_back(node);
} else {
getarray(ar, node->l, rem);
getarray(ar, node->r, rem);
DeleteNode(node);
}
}
Node *makeBST(vector<vector<Node *>> &ar, Node *p, int l, int r) {
if (r - l == 1) {
if (ar[l].size() == 1) {
ar[l][0]->p = p;
return ar[l][0];
} else {
Node *lleaf = ar[l][0], *rleaf = ar[l][1],
*inter =
NewNode(p, lleaf->range[0], rleaf->range[1], lleaf, rleaf);
lleaf->p = inter;
rleaf->p = inter;
inter->upd();
return inter;
}
}
int mid = (l + r) / 2;
Node *cur = NewNode(p, -1, -1, NULL, NULL); // updで範囲決定
cur->l = makeBST(ar, cur, l, mid);
cur->r = makeBST(ar, cur, mid, r);
cur->upd();
return cur;
}
Node *rebuild(Node *node, bool rem = false) {
vector<Node *> ar;
vector<vector<Node *>> f;
Node *nodep = node->p;
bool which = false; // T->r F->l
if (node->p) {
which = node->range[1] == node->p->range[1];
}
ar.reserve(node->sz);
getarray(ar, node, rem);
if (ar.size() == 0) {
root = NULL;
return NULL;
}
int fc = 1;
while (fc * 2 <= ar.size())
fc *= 2;
vector<int> db(fc), dbb(fc);
REP(i, fc) db[i] = i;
shuffle(ALL(db), engine);
REP(i, ar.size() - fc) dbb[db[i]] = 1;
for (int i = 0; ar.size() > i; i++) {
f.push_back(vector<Node *>());
f[f.size() - 1].push_back(ar[i]);
if (dbb[f.size() - 1]) {
i++;
f[f.size() - 1].push_back(ar[i]);
}
}
Node *nn = makeBST(f, nodep, 0, f.size());
if (nodep) {
if (which)
nodep->r = nn;
else
nodep->l = nn;
} else
root = nn;
updpath(nn);
return nn;
}
void remove(Node *node) {
if (node == NULL)
return;
node->removed = true;
node->val = T();
updpath(node);
if (root->dc * 4 > root->sz) {
rebuild(root, true);
}
}
void remove(int t) { remove(search(t)); }
Node *search(int t, bool b = false) {
if (root == NULL)
return NULL;
Node *cur = root;
while (!cur->leaf) {
if (cur->l->range[1] > t) {
cur = cur->l;
} else if (cur->l->range[1] <= t) {
cur = cur->r;
}
}
if (cur->range[0] == t)
return cur;
else
return b ? cur : NULL;
}
Node *insert(int t, T val) {
if (root == NULL) {
return root = NewNode(NULL, t, val);
}
Node *node = search(t, true), *l, *r, *newleaf;
if (node->range[0] == t) {
node->removed = false, node->val = val;
updpath(node);
return node;
}
if (node->range[0] > t) {
r = node, newleaf = l = NewNode(NULL, t, val);
}
if (node->range[0] < t) {
newleaf = r = NewNode(NULL, t, val);
l = node;
}
Node *inter = NewNode(node->p, l->range[0], r->range[1], l, r);
if (node->p) {
if (node->range[1] == node->p->range[1])
node->p->r = inter;
else
node->p->l = inter;
} else
root = inter;
l->p = inter;
r->p = inter;
updpath(inter);
// printf("bef %d:", depth(newleaf));
if (depth(newleaf) > (log(root->sz) / log(3.0 / 2))) {
Node *cur = newleaf, *last = NULL;
while (cur->p != NULL) {
if (cur->sz * 3 > cur->p->sz * 2)
last = cur->p;
cur = cur->p;
}
if (last != NULL)
rebuild(last);
}
return newleaf;
}
T rangequery(int l, int r, Node *node = NULL) { // [l.r)
if (root == NULL)
return T();
if (node == NULL)
node = root;
l = max(l, node->range[0]);
r = min(r, node->range[1]);
if (l == node->range[0] && r == node->range[1])
return node->val;
if (l >= r)
return T();
T ret = T();
ret = ret + rangequery(l, min(r, node->l->range[1]), node->l);
ret = ret + rangequery(max(l, node->r->range[0]), r, node->r);
return ret;
}
};
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll factorial(ll n) { //階乗
static ll memo[400000] = {};
if (n > 0) {
if (memo[n] != 0)
return memo[n];
return memo[n] = n * factorial(n - 1) % MODU;
} else {
return memo[0] = 1;
}
}
ll mod_pow(ll x, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * x % mod;
x = x * x % mod;
n >>= 1;
}
return res;
}
ll divmod(ll a, ll b, ll m) { // a/b(mod m)
// a/b (mod m)
// a*b^-1
// b^-1 * b = 1
// b^(m-1) = 1
// b^(m-2) * b = 1
// b^-1 = b^(m-2)
// a/b = a * b^(m-2)
return (a * 1LL * mod_pow(b, m - 2, m)) % m;
}
ll ncr(ll n, ll r) {
if (n < r)
return 0;
return divmod(factorial(n), (factorial(r) * (factorial(n - r)) % MODU), MODU);
}
signed main(void) {
int n;
string s;
cin >> n >> s;
int cou[26] = {};
for (auto itr : s) {
cou[itr - 'a']++;
}
ll dp[27][27] = {};
dp[0][0] = 1;
REP(i, 27) {
REP(j, 26) {
dp[i + 1][j + 1] += dp[i][j] * cou[i];
dp[i + 1][j] += dp[i][j];
dp[i + 1][j + 1] %= MODU;
dp[i + 1][j] %= MODU;
}
}
int ans = 0;
rep(i, 1, 27) ans += dp[26][i], ans %= MODU;
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <array>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>
#define rep(i, s, n) for (int i = (s); (n) > i; i++)
#define REP(i, n) rep(i, 0, n)
#define RANGE(x, a, b) ((a) <= (x) && (x) < (b))
#define DUPLE(a, b, c, d) \
(RANGE(a, c, d) || RANGE(b, c, d) || RANGE(c, a, b) || RANGE(d, a, b))
#define INCLU(a, b, c, d) (RANGE(a, c, d) && (b, c, d))
#define PW(x) ((x) * (x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007LL
#define bitcheck(a, b) ((a >> b) & 1)
#define bitset(a, b) (a |= (1 << b))
#define bitunset(a, b) (a &= ~(1 << b))
#define MP(a, b) make_pair((a), (b))
#define Manh(a, b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589
#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
std::fill((T *)array, (T *)(array + N), val);
}
pll Dir[8] = { //移動
{0, 1}, {-1, 0}, {1, 0}, {0, -1}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
//[a, b)
#define Getsum(ar, a, b) (ar[b] - ar[a])
#define INF 10000000000000000LL
struct Edge {
ll from, to;
ll w;
};
typedef vector<vector<Edge>> Graph;
template <typename T> // Tのデフォルトコンストラクタが単位元となる
class ScapegoatTree_Leaf {
public:
struct Node {
int range[2]; // [range[0], range[1])
T val;
Node *p = NULL, *l = NULL, *r = NULL;
bool removed = false, leaf;
int sz = 1, dc = 0, coin = 0;
Node(Node *par, int rangel, int ranger, Node *left, Node *right)
: leaf(false), val(T()), p(par), l(left), r(right) {
range[0] = rangel, range[1] = ranger;
}
Node(Node *par, int t, T _val) : leaf(true), val(_val), p(par) {
range[0] = t, range[1] = t + 1;
}
void upd() {
if (!leaf) {
sz = 1 + l->sz + r->sz;
dc = removed + l->dc + r->dc;
range[0] = l->range[0];
range[1] = r->range[1];
val = l->val + r->val;
} else {
dc = removed;
}
}
int size() { return sz - dc; }
};
#define MAXPOOLSIZE 3000000
mt19937 engine;
Node *root = NULL;
int poolcou = 0;
Node *nodepool[MAXPOOLSIZE] = {};
void updpath(Node *node) {
Node *cur = node;
while (cur != NULL) {
cur->upd();
cur = cur->p;
}
}
int depth(Node *node) {
Node *cur = node;
int c = 0;
while (cur != root) {
cur = cur->p;
c++;
}
return c;
}
void DeleteNode(Node *node) {
nodepool[poolcou] = node;
poolcou++;
}
Node *NewNode(Node *par, int rangel, int ranger, Node *left, Node *right) {
Node *ret;
if (poolcou) {
ret = nodepool[poolcou - 1], poolcou--;
ret->removed = false, ret->sz = 1, ret->dc = 0, ret->val = T(),
ret->leaf = false, ret->p = par, ret->range[0] = rangel,
ret->range[1] = ranger, ret->l = left, ret->r = right;
} else
ret = new Node(par, rangel, ranger, left, right);
return ret;
}
Node *NewNode(Node *par, int t, T _val) {
Node *ret;
if (poolcou) {
ret = nodepool[poolcou - 1], poolcou--;
ret->removed = false, ret->sz = 1, ret->dc = 0, ret->leaf = true,
ret->p = par, ret->range[0] = t, ret->range[1] = t + 1, ret->val = _val;
} else
ret = new Node(par, t, _val);
return ret;
}
void getarray(vector<Node *> &ar, Node *node, bool rem) {
if (node->leaf) {
if (node->removed && rem)
DeleteNode(node);
else
ar.push_back(node);
} else {
getarray(ar, node->l, rem);
getarray(ar, node->r, rem);
DeleteNode(node);
}
}
Node *makeBST(vector<vector<Node *>> &ar, Node *p, int l, int r) {
if (r - l == 1) {
if (ar[l].size() == 1) {
ar[l][0]->p = p;
return ar[l][0];
} else {
Node *lleaf = ar[l][0], *rleaf = ar[l][1],
*inter =
NewNode(p, lleaf->range[0], rleaf->range[1], lleaf, rleaf);
lleaf->p = inter;
rleaf->p = inter;
inter->upd();
return inter;
}
}
int mid = (l + r) / 2;
Node *cur = NewNode(p, -1, -1, NULL, NULL); // updで範囲決定
cur->l = makeBST(ar, cur, l, mid);
cur->r = makeBST(ar, cur, mid, r);
cur->upd();
return cur;
}
Node *rebuild(Node *node, bool rem = false) {
vector<Node *> ar;
vector<vector<Node *>> f;
Node *nodep = node->p;
bool which = false; // T->r F->l
if (node->p) {
which = node->range[1] == node->p->range[1];
}
ar.reserve(node->sz);
getarray(ar, node, rem);
if (ar.size() == 0) {
root = NULL;
return NULL;
}
int fc = 1;
while (fc * 2 <= ar.size())
fc *= 2;
vector<int> db(fc), dbb(fc);
REP(i, fc) db[i] = i;
shuffle(ALL(db), engine);
REP(i, ar.size() - fc) dbb[db[i]] = 1;
for (int i = 0; ar.size() > i; i++) {
f.push_back(vector<Node *>());
f[f.size() - 1].push_back(ar[i]);
if (dbb[f.size() - 1]) {
i++;
f[f.size() - 1].push_back(ar[i]);
}
}
Node *nn = makeBST(f, nodep, 0, f.size());
if (nodep) {
if (which)
nodep->r = nn;
else
nodep->l = nn;
} else
root = nn;
updpath(nn);
return nn;
}
void remove(Node *node) {
if (node == NULL)
return;
node->removed = true;
node->val = T();
updpath(node);
if (root->dc * 4 > root->sz) {
rebuild(root, true);
}
}
void remove(int t) { remove(search(t)); }
Node *search(int t, bool b = false) {
if (root == NULL)
return NULL;
Node *cur = root;
while (!cur->leaf) {
if (cur->l->range[1] > t) {
cur = cur->l;
} else if (cur->l->range[1] <= t) {
cur = cur->r;
}
}
if (cur->range[0] == t)
return cur;
else
return b ? cur : NULL;
}
Node *insert(int t, T val) {
if (root == NULL) {
return root = NewNode(NULL, t, val);
}
Node *node = search(t, true), *l, *r, *newleaf;
if (node->range[0] == t) {
node->removed = false, node->val = val;
updpath(node);
return node;
}
if (node->range[0] > t) {
r = node, newleaf = l = NewNode(NULL, t, val);
}
if (node->range[0] < t) {
newleaf = r = NewNode(NULL, t, val);
l = node;
}
Node *inter = NewNode(node->p, l->range[0], r->range[1], l, r);
if (node->p) {
if (node->range[1] == node->p->range[1])
node->p->r = inter;
else
node->p->l = inter;
} else
root = inter;
l->p = inter;
r->p = inter;
updpath(inter);
// printf("bef %d:", depth(newleaf));
if (depth(newleaf) > (log(root->sz) / log(3.0 / 2))) {
Node *cur = newleaf, *last = NULL;
while (cur->p != NULL) {
if (cur->sz * 3 > cur->p->sz * 2)
last = cur->p;
cur = cur->p;
}
if (last != NULL)
rebuild(last);
}
return newleaf;
}
T rangequery(int l, int r, Node *node = NULL) { // [l.r)
if (root == NULL)
return T();
if (node == NULL)
node = root;
l = max(l, node->range[0]);
r = min(r, node->range[1]);
if (l == node->range[0] && r == node->range[1])
return node->val;
if (l >= r)
return T();
T ret = T();
ret = ret + rangequery(l, min(r, node->l->range[1]), node->l);
ret = ret + rangequery(max(l, node->r->range[0]), r, node->r);
return ret;
}
};
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll factorial(ll n) { //階乗
static ll memo[400000] = {};
if (n > 0) {
if (memo[n] != 0)
return memo[n];
return memo[n] = n * factorial(n - 1) % MODU;
} else {
return memo[0] = 1;
}
}
ll mod_pow(ll x, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * x % mod;
x = x * x % mod;
n >>= 1;
}
return res;
}
ll divmod(ll a, ll b, ll m) { // a/b(mod m)
// a/b (mod m)
// a*b^-1
// b^-1 * b = 1
// b^(m-1) = 1
// b^(m-2) * b = 1
// b^-1 = b^(m-2)
// a/b = a * b^(m-2)
return (a * 1LL * mod_pow(b, m - 2, m)) % m;
}
ll ncr(ll n, ll r) {
if (n < r)
return 0;
return divmod(factorial(n), (factorial(r) * (factorial(n - r)) % MODU), MODU);
}
signed main(void) {
int n;
string s;
cin >> n >> s;
int cou[26] = {};
for (auto itr : s) {
cou[itr - 'a']++;
}
ll dp[27][27] = {};
dp[0][0] = 1;
REP(i, 26) {
REP(j, 26) {
dp[i + 1][j + 1] += dp[i][j] * cou[i];
dp[i + 1][j] += dp[i][j];
dp[i + 1][j + 1] %= MODU;
dp[i + 1][j] %= MODU;
}
}
int ans = 0;
rep(i, 1, 27) ans += dp[26][i], ans %= MODU;
cout << ans << endl;
return 0;
} | [
"literal.number.change",
"call.arguments.change"
] | 906,666 | 906,667 | u152129372 | cpp |
p03090 | #include <bits/stdc++.h>
using namespace std;
#define FOR(i, l, r) for (long long i = (l); i < (r); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FOR(i, 1, n + 1)
#define RFOR(i, l, r) for (long long i = (l); i >= (r); --i)
#define RREP(i, n) RFOR(i, N - 1, 0)
#define RREPS(i, n) RFOR(i, N, 1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
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;
}
const int INF = 1e18;
const int MOD = 1e9 + 7;
signed main() {
int N;
cin >> N;
bool G[N + 1][N + 1];
REP(i, N + 1) REP(j, N + 1) G[i][j] = true;
REP(i, N + 1) G[i][i] = false;
if (N % 2 == 0) {
cout << (N - 2) * N / 2 << endl;
REPS(i, N) { G[i][N - i] = false; }
} else {
cout << (N - 1) * (N - 1) / 2 << endl;
REPS(i, N) { G[i][N - i] = false; }
}
REPS(i, N) REPS(j, N) if (G[i][j]) {
cout << i << " " << j << endl;
G[i][j] = G[j][i] = false;
}
} | #include <bits/stdc++.h>
using namespace std;
#define FOR(i, l, r) for (long long i = (l); i < (r); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FOR(i, 1, n + 1)
#define RFOR(i, l, r) for (long long i = (l); i >= (r); --i)
#define RREP(i, n) RFOR(i, N - 1, 0)
#define RREPS(i, n) RFOR(i, N, 1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
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;
}
const int INF = 1e18;
const int MOD = 1e9 + 7;
signed main() {
int N;
cin >> N;
bool G[N + 1][N + 1];
REP(i, N + 1) REP(j, N + 1) G[i][j] = true;
REP(i, N + 1) G[i][i] = false;
if (N % 2 == 0) {
cout << (N - 2) * N / 2 << endl;
REPS(i, N) { G[i][N - i + 1] = false; }
} else {
cout << (N - 1) * (N - 1) / 2 << endl;
REPS(i, N) { G[i][N - i] = false; }
}
REPS(i, N) REPS(j, N) if (G[i][j]) {
cout << i << " " << j << endl;
G[i][j] = G[j][i] = false;
}
} | [
"assignment.change"
] | 906,672 | 906,673 | u342075214 | cpp |
p03090 | #define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (auto i = a; i < b; i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
// ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
int main() {
int n;
cin >> n;
int sum = n % 2 ? n : n + 1;
printf("%d\n", (sum - 1) * sum / 2 - n / 2);
rep(i, 0, n) {
rep(i2, i + 1, n) {
if (i + i2 + 2 == sum)
continue;
printf("%d %d\n", i + 1, i2 + 1);
}
}
return 0;
}
| #define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (auto i = a; i < b; i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
// ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
int main() {
int n;
cin >> n;
int sum = n % 2 ? n : n + 1;
printf("%d\n", (n - 1) * n / 2 - n / 2);
rep(i, 0, n) {
rep(i2, i + 1, n) {
if (i + i2 + 2 == sum)
continue;
printf("%d %d\n", i + 1, i2 + 1);
}
}
return 0;
}
| [
"identifier.change",
"call.arguments.change",
"expression.operation.binary.change",
"io.output.change"
] | 906,679 | 906,680 | u128572736 | cpp |
p03090 | #include <bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
using f64 = double;
constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;
void solve() {
i64 n;
cin >> n;
cout << n * (n - 1) / 2 - (n - 1) / 2 << endl;
for (i64 a = 1; a + 1 <= n; a++) {
for (i64 b = a + 1; b <= n; b++) {
if (a + b == n + (n % 2 == 0))
continue;
cout << a << " " << b << endl;
}
}
}
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
solve();
}
| #include <bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
using f64 = double;
constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;
void solve() {
i64 n;
cin >> n;
cout << n * (n - 1) / 2 - n / 2 << endl;
for (i64 a = 1; a + 1 <= n; a++) {
for (i64 b = a + 1; b <= n; b++) {
if (a + b == n + (n % 2 == 0))
continue;
cout << a << " " << b << endl;
}
}
}
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
solve();
}
| [] | 906,683 | 906,684 | u820225607 | cpp |
p03090 | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define exrep(i, a, b) for (ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
int main() {
ll n;
cin >> n;
ll x = n;
if (n % 2 == 0) {
x++;
}
out(n * (n + 1) / 2 - n / 2);
exrep(i, 1, n - 2) {
exrep(j, i + 1, n - 1) {
if (i + j == x) {
continue;
}
cout << i << " " << j << "\n";
}
}
re0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define exrep(i, a, b) for (ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
int main() {
ll n;
cin >> n;
ll x = n;
if (n % 2 == 0) {
x++;
}
out(n * (n - 1) / 2 - n / 2);
exrep(i, 1, n - 1) {
exrep(j, i + 1, n) {
if (i + j == x) {
continue;
}
cout << i << " " << j << "\n";
}
}
re0;
} | [
"misc.opposites",
"expression.operator.arithmetic.change",
"call.arguments.change",
"expression.operation.binary.change",
"literal.number.change",
"expression.operation.binary.remove"
] | 906,691 | 906,692 | u828388155 | cpp |
p03090 | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define exrep(i, a, b) for (ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
int main() {
ll n;
cin >> n;
ll m = n * (n - 1) / 2 - n / 2;
out(m);
ll k = n;
if (n % 2 == 0) {
k++;
}
exrep(i, 1, n - 1) {
exrep(j, i + 1, n) {
if (i + j == k) {
continue;
}
cout << i << " " << j;
}
cout << "\n";
}
re0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define exrep(i, a, b) for (ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
int main() {
ll n;
cin >> n;
ll m = n * (n - 1) / 2 - n / 2;
out(m);
ll k = n;
if (n % 2 == 0) {
k++;
}
exrep(i, 1, n - 1) {
exrep(j, i + 1, n) {
if (i + j == k) {
continue;
}
cout << i << " " << j << "\n";
}
}
re0;
} | [] | 906,693 | 906,694 | u828388155 | cpp |
p03090 | #include <bits/stdc++.h>
#define debug(x) \
cout << "DEBUG" \
<< " " << #x << ":" << x << '\n'
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++) // 0-indexed昇順
#define rep1(i, n) for (int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--) // 0-indexed降順
#define rrep1(i, n) for (int i = ((int)(n)); i >= 1; i--) // 1-indexed降順
#define all(x) (x).begin(), (x).end()
using namespace std;
template <typename T> using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>; // 2次元配列
using PII = pair<int_fast32_t, int_fast32_t>;
template <class T> using maxheap = std::priority_queue<T>;
template <class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <class T, class U> inline bool chmax(T &a, const U &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T, class U> inline bool chmin(T &a, const U &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL << 62) - 1;
constexpr int inf = (1 << 30) - 1;
const int mod = 1000000007;
// const int mod = 998244353;
/*FUNCs=================================================*/
/*MAIN==================================================*/
signed main() {
int START_TIME = clock();
cin.tie(nullptr);
ios::sync_with_stdio(false); // cin cout 高速化
// cout << fixed << setprecision(15);
i32 n;
cin >> n;
vec<vi> graph(n);
i32 m = 0;
for (int i = 0; i < n - 1; ++i) {
for (int j = i + 1; j < n; ++j) {
int v = i + 1;
int u = j + 1;
if (n & 1) {
if (u + v == n)
continue;
graph[i].push_back(j);
++m;
} else {
if (u + v != n + 1)
continue;
graph[i].push_back(j);
++m;
}
}
}
// output
cout << m << '\n';
rep(u, n) {
for (auto v : graph[u])
cout << u + 1 << ' ' << v + 1 << '\n';
}
// printf("ExecutionTime: %d
// /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}
| #include <bits/stdc++.h>
#define debug(x) \
cout << "DEBUG" \
<< " " << #x << ":" << x << '\n'
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++) // 0-indexed昇順
#define rep1(i, n) for (int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--) // 0-indexed降順
#define rrep1(i, n) for (int i = ((int)(n)); i >= 1; i--) // 1-indexed降順
#define all(x) (x).begin(), (x).end()
using namespace std;
template <typename T> using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>; // 2次元配列
using PII = pair<int_fast32_t, int_fast32_t>;
template <class T> using maxheap = std::priority_queue<T>;
template <class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <class T, class U> inline bool chmax(T &a, const U &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T, class U> inline bool chmin(T &a, const U &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL << 62) - 1;
constexpr int inf = (1 << 30) - 1;
const int mod = 1000000007;
// const int mod = 998244353;
/*FUNCs=================================================*/
/*MAIN==================================================*/
signed main() {
int START_TIME = clock();
cin.tie(nullptr);
ios::sync_with_stdio(false); // cin cout 高速化
// cout << fixed << setprecision(15);
i32 n;
cin >> n;
vec<vi> graph(n);
i32 m = 0;
for (int i = 0; i < n - 1; ++i) {
for (int j = i + 1; j < n; ++j) {
int v = i + 1;
int u = j + 1;
if (n & 1) {
if (u + v == n)
continue;
graph[i].push_back(j);
++m;
} else {
if (u + v == n + 1)
continue;
graph[i].push_back(j);
++m;
}
}
}
// output
cout << m << '\n';
rep(u, n) {
for (auto v : graph[u])
cout << u + 1 << ' ' << v + 1 << '\n';
}
// printf("ExecutionTime: %d
// /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}
| [
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 906,701 | 906,702 | u457985479 | cpp |
p03090 | #include <bits/stdc++.h>
using namespace std;
#define REP(i, init, n) for (int i = (int)(init); i < (int)(n); i++)
int main() {
int N;
cin >> N;
vector<vector<int>> G(N);
int cnt = 0;
REP(i, 1, N + 1) REP(j, i, N + 1) {
if (i == j)
continue;
if (i + j != N + 1) {
G[i - 1].emplace_back(j);
cnt++;
}
}
cout << cnt << endl;
REP(i, 0, N) {
REP(j, 0, G[i].size()) { cout << i + 1 << " " << G[i][j] << endl; }
}
} | #include <bits/stdc++.h>
using namespace std;
#define REP(i, init, n) for (int i = (int)(init); i < (int)(n); i++)
int main() {
int N;
cin >> N;
vector<vector<int>> G(N);
int cnt = 0;
REP(i, 1, N + 1) REP(j, i, N + 1) {
if (i == j)
continue;
if (i + j != N + (N + 1) % 2) {
G[i - 1].emplace_back(j);
cnt++;
}
}
cout << cnt << endl;
REP(i, 0, N) {
REP(j, 0, G[i].size()) { cout << i + 1 << " " << G[i][j] << endl; }
}
} | [
"control_flow.branch.if.condition.change"
] | 906,703 | 906,704 | u559424030 | cpp |
p03090 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define MAX 1000000
#define MOD 1000000007
#define INF 100000000000000
int main() {
int N;
cin >> N;
if (N % 2 == 0) {
cout << N * (N - 2) / 2 << endl;
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
if (j == i || j == N + 1 - i) {
continue;
}
cout << i << " " << j << endl;
}
}
} else {
cout << (N - 1) * (N - 1) / 2 << endl;
for (int i = 1; i < N; i++) {
for (int j = 1; j < N; j++) {
if (j == i || j == N - i) {
continue;
}
cout << i << " " << j << endl;
}
}
for (int i = 1; i < N; i++) {
cout << i << " " << N << endl;
}
}
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define MAX 1000000
#define MOD 1000000007
#define INF 100000000000000
int main() {
int N;
cin >> N;
if (N % 2 == 0) {
cout << N * (N - 2) / 2 << endl;
for (int i = 1; i <= N; i++) {
for (int j = i + 1; j <= N; j++) {
if (j == i || j == N + 1 - i) {
continue;
}
cout << i << " " << j << endl;
}
}
} else {
cout << (N - 1) * (N - 1) / 2 << endl;
for (int i = 1; i < N; i++) {
for (int j = i + 1; j < N; j++) {
if (j == i || j == N - i) {
continue;
}
cout << i << " " << j << endl;
}
}
for (int i = 1; i < N; i++) {
cout << i << " " << N << endl;
}
}
}
| [
"control_flow.loop.for.initializer.change"
] | 906,707 | 906,708 | u630211216 | cpp |
p03090 | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
int num = N + (N + 1) % 2;
int M = (N * (N + 1)) / 2 - num;
cout << M << endl;
for (int i = 1; i <= N; i++) {
for (int j = i + 1; j <= N; j++) {
if (i + j != num) {
cout << i << " " << j << endl;
}
}
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
int num = N + (N + 1) % 2;
int M = (N * (N - 1)) / 2 - N / 2;
cout << M << endl;
for (int i = 1; i <= N; i++) {
for (int j = i + 1; j <= N; j++) {
if (i + j != num) {
cout << i << " " << j << endl;
}
}
}
} | [
"misc.opposites",
"expression.operator.arithmetic.change",
"expression.operation.binary.change",
"identifier.change"
] | 906,711 | 906,712 | u943966256 | cpp |
p03090 | //#pragma once
#include <algorithm>
#include <iostream>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
typedef pair<long long, long long> pl;
long long N, M, k, a, b, c, d, e, H, W, X;
long long A[200][200];
long long B[200002] = {};
long long tt[20000] = {};
bool f;
bool ff;
string S, SS;
set<long long> sll;
pl buf;
vector<long long> vpl;
vector<long long> vl;
int main() {
cin >> N;
if (N % 2 == 0) {
for (int i = 1; i <= N; i++) {
for (int j = i + 1; j <= N; j++) {
if (j != N + 1 - i) {
vl.push_back(i);
vpl.push_back(j);
}
}
}
} else {
for (int i = 1; i <= N; i++) {
for (int j = i + 1; j <= N; j++) {
if (j != N - i) {
vl.push_back(i);
vpl.push_back(j);
}
}
}
}
cout << vl.size() << endl;
for (int i = 0; i < vl.size(); i++) {
cout << vl[i] << vpl[i] << endl;
}
return 0;
} | //#pragma once
#include <algorithm>
#include <iostream>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
typedef pair<long long, long long> pl;
long long N, M, k, a, b, c, d, e, H, W, X;
long long A[200][200];
long long B[200002] = {};
long long tt[20000] = {};
bool f;
bool ff;
string S, SS;
set<long long> sll;
pl buf;
vector<long long> vpl;
vector<long long> vl;
int main() {
cin >> N;
if (N % 2 == 0) {
for (int i = 1; i <= N; i++) {
for (int j = i + 1; j <= N; j++) {
if (j != N + 1 - i) {
vl.push_back(i);
vpl.push_back(j);
}
}
}
} else {
for (int i = 1; i <= N; i++) {
for (int j = i + 1; j <= N; j++) {
if (j != N - i) {
vl.push_back(i);
vpl.push_back(j);
}
}
}
}
cout << vl.size() << endl;
for (int i = 0; i < vl.size(); i++) {
cout << vl[i] << ' ' << vpl[i] << endl;
}
return 0;
} | [
"io.output.change"
] | 906,715 | 906,716 | u058317639 | cpp |
p03090 | #include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define FOR(k, m, n) for (ll(k) = (m); (k) < (n); (k)++)
#define REP(i, n) FOR((i), 0, (n))
#define WAITING(str) \
int str; \
std::cin >> str;
#define DEBUGING(str) cout << #str << " " str << endl
constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007; // 10^9+7
int main() {
int N;
cin >> N;
set<set<ll>> st;
if (N % 2 == 0) {
FOR(i, 1, N) st.insert({i, N + 1 - i});
} else {
FOR(i, 1, N) st.insert({i, N + 1 - i});
}
vector<string> res;
FOR(i, 1, N) FOR(j, i + 1, N + 1) if (st.find({i, j}) == st.end()) {
stringstream ss;
ss << i << " " << j;
res.push_back(ss.str());
}
cout << res.size() << endl;
for (auto row : res)
cout << row << endl;
return 0;
}
| #include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define FOR(k, m, n) for (ll(k) = (m); (k) < (n); (k)++)
#define REP(i, n) FOR((i), 0, (n))
#define WAITING(str) \
int str; \
std::cin >> str;
#define DEBUGING(str) cout << #str << " " str << endl
constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007; // 10^9+7
int main() {
int N;
cin >> N;
set<set<ll>> st;
if (N % 2 == 0) {
FOR(i, 1, N) st.insert({i, N + 1 - i});
} else {
FOR(i, 1, N - 1) st.insert({i, N - i});
}
vector<string> res;
FOR(i, 1, N) FOR(j, i + 1, N + 1) if (st.find({i, j}) == st.end()) {
stringstream ss;
ss << i << " " << j;
res.push_back(ss.str());
}
cout << res.size() << endl;
for (auto row : res)
cout << row << endl;
return 0;
}
| [
"expression.operation.binary.remove"
] | 906,721 | 906,722 | u692632484 | cpp |
p03090 | #include <bits/stdc++.h>
#define be(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod = 1000000007;
#define doublecout(a) cout << fixed << setprecision(10) << a << endl;
int main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<pair<int, int>> v;
int m = (n % 2) ? n + 1 : n;
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if (i + j != m) {
v.pb(make_pair(i, j));
}
}
}
cout << (v.size()) << endl;
for (auto i : v) {
cout << i.first << " " << i.second << endl;
}
return 0;
}
| #include <bits/stdc++.h>
#define be(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod = 1000000007;
#define doublecout(a) cout << fixed << setprecision(10) << a << endl;
int main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<pair<int, int>> v;
int m = (n % 2) ? n : n + 1;
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if (i + j != m) {
v.pb(make_pair(i, j));
}
}
}
cout << (v.size()) << endl;
for (auto i : v) {
cout << i.first << " " << i.second << endl;
}
return 0;
}
| [
"expression.operation.binary.remove"
] | 906,723 | 906,724 | u192903163 | cpp |
p03090 | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL << 60
const double PI = 3.14159265358979323846;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
if (N % 2 == 0) {
cout << N * (N - 2) / 2 << endl;
for (int i = 1; 2 * i <= N; i++) {
for (int j = i + 1; j <= N; j++) {
if (i + j != N + 1)
cout << i << " " << j << endl;
}
}
} else {
cout << (N - 1) * (N - 1) / 2 << endl;
for (int i = 1; 2 * i < N; i++) {
for (int j = i + 1; j < N; j++) {
if (i + j != N)
cout << i << " " << j << endl;
}
}
for (int i = 1; i < N; i++)
cout << i << " " << N << endl;
}
return 0;
} | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL << 60
const double PI = 3.14159265358979323846;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
if (N % 2 == 0) {
cout << N * (N - 2) / 2 << endl;
for (int i = 1; i <= N; i++) {
for (int j = i + 1; j <= N; j++) {
if (i + j != N + 1)
cout << i << " " << j << endl;
}
}
} else {
cout << (N - 1) * (N - 1) / 2 << endl;
for (int i = 1; i < N; i++) {
for (int j = i + 1; j < N; j++) {
if (i + j != N)
cout << i << " " << j << endl;
}
}
for (int i = 1; i < N; i++)
cout << i << " " << N << endl;
}
return 0;
} | [
"control_flow.loop.for.condition.change",
"expression.operation.binary.remove"
] | 906,730 | 906,731 | u774652316 | cpp |
p03090 | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll N;
cin >> N;
ll M = N * (N - 1) / 2 - (N - 1) / 2;
cout << M << "\n";
ll p;
if (N % 2 == 0) {
p = N + 1;
} else {
p = N;
}
for (ll i = 1; i <= N; i++) {
for (ll j = i + 1; j <= N; j++) {
if (i + j == p)
continue;
cout << i << " " << j << "\n";
}
}
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll N;
cin >> N;
ll M = N * (N - 1) / 2 - N / 2;
cout << M << "\n";
ll p;
if (N % 2 == 0) {
p = N + 1;
} else {
p = N;
}
for (ll i = 1; i <= N; i++) {
for (ll j = i + 1; j <= N; j++) {
if (i + j == p)
continue;
cout << i << " " << j << "\n";
}
}
} | [] | 906,757 | 906,758 | u017271745 | cpp |
p03090 | #include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = (int)(s); i < (int)(t); ++i)
#define each(a, b) for (auto &(a) : (b))
#define all(v) (v).begin(), (v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)), v.erase(unique(all(v)), v.end())
#define cmx(x, y) x = max(x, y)
#define cmn(x, y) x = min(x, y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout << #x << " = " << (x) << endl
#define sar(a, n) \
{ \
cout << #a << ":"; \
rep(pachico, n) cout << " " << a[pachico]; \
cout << endl; \
}
using namespace std;
template <typename S, typename T> auto &operator<<(ostream &o, pair<S, T> p) {
return o << "{" << p.fi << "," << p.se << "}";
}
template <typename T> auto &operator<<(ostream &o, set<T> s) {
for (auto &e : s)
o << e << " ";
return o;
}
template <typename S, typename T, typename U>
auto &operator<<(ostream &o, priority_queue<S, T, U> q) {
while (!q.empty())
o << q.top() << " ", q.pop();
return o;
}
template <typename K, typename T> auto &operator<<(ostream &o, map<K, T> &m) {
for (auto &e : m)
o << e << " ";
return o;
}
template <typename T> auto &operator<<(ostream &o, vector<T> v) {
for (auto &e : v)
o << e << " ";
return o;
}
void ashow() { cout << endl; }
template <typename T, typename... A> void ashow(T t, A... a) {
cout << t << " ";
ashow(a...);
}
template <typename S, typename T, typename U> struct TRI {
S fi;
T se;
U th;
TRI() {}
TRI(S f, T s, U t) : fi(f), se(s), th(t) {}
bool operator<(const TRI &_) const {
return (fi == _.fi) ? ((se == _.se) ? (th < _.th) : (se < _.se))
: (fi < _.fi);
}
};
template <typename S, typename T, typename U>
auto &operator<<(ostream &o, TRI<S, T, U> &t) {
return o << "{" << t.fi << "," << t.se << "," << t.th << "}";
}
typedef pair<int, int> P;
typedef pair<ll, ll> pll;
typedef TRI<int, int, int> tri;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef vector<string> vs;
const int MAX_N = 100005;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
if (n % 2 == 0) {
cout << n * (n - 2) / 2 << "\n";
srep(i, 1, n + 1) {
srep(j, i + 1, n + 1) {
if (i + j == n + 1)
continue;
cout << i << " " << j << "\n";
}
}
} else {
cout << n * (n - 2) / 2 + n - 1 << "\n";
srep(i, 1, n) {
srep(j, i + 1, n) {
if (i + j == n)
continue;
cout << i << " " << j << "\n";
}
}
srep(i, 1, n) { cout << i << " " << n << "\n"; }
}
return 0;
}
| #include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = (int)(s); i < (int)(t); ++i)
#define each(a, b) for (auto &(a) : (b))
#define all(v) (v).begin(), (v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)), v.erase(unique(all(v)), v.end())
#define cmx(x, y) x = max(x, y)
#define cmn(x, y) x = min(x, y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout << #x << " = " << (x) << endl
#define sar(a, n) \
{ \
cout << #a << ":"; \
rep(pachico, n) cout << " " << a[pachico]; \
cout << endl; \
}
using namespace std;
template <typename S, typename T> auto &operator<<(ostream &o, pair<S, T> p) {
return o << "{" << p.fi << "," << p.se << "}";
}
template <typename T> auto &operator<<(ostream &o, set<T> s) {
for (auto &e : s)
o << e << " ";
return o;
}
template <typename S, typename T, typename U>
auto &operator<<(ostream &o, priority_queue<S, T, U> q) {
while (!q.empty())
o << q.top() << " ", q.pop();
return o;
}
template <typename K, typename T> auto &operator<<(ostream &o, map<K, T> &m) {
for (auto &e : m)
o << e << " ";
return o;
}
template <typename T> auto &operator<<(ostream &o, vector<T> v) {
for (auto &e : v)
o << e << " ";
return o;
}
void ashow() { cout << endl; }
template <typename T, typename... A> void ashow(T t, A... a) {
cout << t << " ";
ashow(a...);
}
template <typename S, typename T, typename U> struct TRI {
S fi;
T se;
U th;
TRI() {}
TRI(S f, T s, U t) : fi(f), se(s), th(t) {}
bool operator<(const TRI &_) const {
return (fi == _.fi) ? ((se == _.se) ? (th < _.th) : (se < _.se))
: (fi < _.fi);
}
};
template <typename S, typename T, typename U>
auto &operator<<(ostream &o, TRI<S, T, U> &t) {
return o << "{" << t.fi << "," << t.se << "," << t.th << "}";
}
typedef pair<int, int> P;
typedef pair<ll, ll> pll;
typedef TRI<int, int, int> tri;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef vector<string> vs;
const int MAX_N = 100005;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
if (n % 2 == 0) {
cout << n * (n - 2) / 2 << "\n";
srep(i, 1, n + 1) {
srep(j, i + 1, n + 1) {
if (i + j == n + 1)
continue;
cout << i << " " << j << "\n";
}
}
} else {
cout << (n - 1) * (n - 3) / 2 + n - 1 << "\n";
srep(i, 1, n) {
srep(j, i + 1, n) {
if (i + j == n)
continue;
cout << i << " " << j << "\n";
}
}
srep(i, 1, n) { cout << i << " " << n << "\n"; }
}
return 0;
}
| [
"literal.number.change",
"io.output.change"
] | 906,761 | 906,762 | u509674552 | cpp |
p03096 | #include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
long long dp[200000];
long long sum[200000];
map<long long, long long> m;
void solve(long long N, vector<long long> C) {
dp[0] = 1;
sum[0] = 1;
for (int i = 1; i < N; i++)
m[C[i]] = -1;
m[C[0]] = 0;
for (int i = 1; i < N; i++) {
if (-1 != m[C[i]] && i - 1 != m[C[i]]) {
dp[i] = sum[m[C[i]]] * 2 % MOD;
sum[i] = (sum[i - 1] + dp[m[C[i]]]) % MOD;
// cout << i << " " << m[C[i]]-1 << " " << res << "\n";
} else {
dp[i] = dp[i - 1];
sum[i] = sum[i - 1];
}
m[C[i]] = i;
}
cout << sum[N - 1] << "\n";
}
int main() {
long long N;
scanf("%lld", &N);
vector<long long> C(N - 1 + 1);
for (int i = 0; i <= N - 1; i++) {
scanf("%lld", &C[i]);
}
solve(N, C);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
long long dp[200000];
long long sum[200000];
map<long long, long long> m;
void solve(long long N, vector<long long> C) {
dp[0] = 1;
sum[0] = 1;
for (int i = 1; i < N; i++)
m[C[i]] = -1;
m[C[0]] = 0;
for (int i = 1; i < N; i++) {
if (-1 != m[C[i]] && i - 1 != m[C[i]]) {
dp[i] = sum[m[C[i]]] * 2 % MOD;
sum[i] = (sum[i - 1] + sum[m[C[i]]]) % MOD;
// cout << i << " " << m[C[i]]-1 << " " << res << "\n";
} else {
dp[i] = dp[i - 1];
sum[i] = sum[i - 1];
}
m[C[i]] = i;
}
// long long res = 0;
// map<long long, long long> m2;
// for(int i = 0 ; i < N ; i++) {
// if (m2[C[i]] == 0) {
// res += dp[m[C[i]]];
// m2[C[i]]++;
// }
// }
// cout << res << "\n";
cout << sum[N - 1] << "\n";
}
int main() {
long long N;
scanf("%lld", &N);
vector<long long> C(N - 1 + 1);
for (int i = 0; i <= N - 1; i++) {
scanf("%lld", &C[i]);
}
solve(N, C);
return 0;
}
| [
"assignment.value.change",
"identifier.change",
"expression.operation.binary.change"
] | 906,773 | 906,774 | u709604332 | cpp |
p03096 | #include <stdio.h>
int main(void) {
int n;
scanf("%d", &n);
int c[n];
for (int i = 0; i < n; i++) {
scanf("%d", c + i);
}
int d[200005];
long long f[n];
f[0] = 1;
int e[200005];
for (int i = 0; i < n; i++)
e[i] = 0;
long long p = 1000000007;
e[c[0]]++;
d[c[0]] = 0;
for (int i = 1; i < n; i++) {
if ((e[c[i]] == 0) || c[i] == c[i - 1]) {
f[i] = f[i - 1];
} else {
f[i] = f[i - 1] + f[d[c[i]] + 1];
f[i] %= p;
}
d[c[i]] = i;
e[c[i]]++;
}
printf("%lld\n", f[n - 1]);
} | #include <stdio.h>
int main(void) {
int n;
scanf("%d", &n);
int c[n];
for (int i = 0; i < n; i++) {
scanf("%d", c + i);
}
int d[200005];
long long f[n];
f[0] = 1;
int e[200005];
for (int i = 0; i < 200005; i++)
e[i] = 0;
long long p = 1000000007;
e[c[0]]++;
d[c[0]] = 0;
for (int i = 1; i < n; i++) {
if ((e[c[i]] == 0) || c[i] == c[i - 1]) {
f[i] = f[i - 1];
} else {
f[i] = f[i - 1] + f[d[c[i]]];
f[i] %= p;
}
d[c[i]] = i;
e[c[i]]++;
}
printf("%lld\n", f[n - 1]);
} | [
"identifier.replace.remove",
"literal.replace.add",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change",
"expression.operation.binary.remove"
] | 906,779 | 906,780 | u546925116 | cpp |
p03096 | #include <bits/stdc++.h>
#define M 200005
#define ll long long
#define P 1000000007
using namespace std;
int n;
int col[M], nw[M];
ll dp[M], res[M]; // i结尾方案(必取) 前缀 上个位置
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &col[i]);
int sz = 0;
for (int i = 1; i <= n; i++)
if (col[i] != col[i - 1])
nw[++sz] = col[i];
for (int i = 1; i <= sz; i++) {
dp[i] = res[nw[i]];
res[nw[i]] = (res[nw[i]] + dp[i - 1] + 1) % P;
dp[i] = (dp[i] + dp[i - 1]) % P;
}
printf("%lld\n", (dp[n] + 1) % P);
return 0;
} | #include <bits/stdc++.h>
#define M 200005
#define ll long long
#define P 1000000007
using namespace std;
int n;
int col[M], nw[M];
ll dp[M], res[M]; // i结尾方案(必取) 前缀 上个位置
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &col[i]);
int sz = 0;
for (int i = 1; i <= n; i++)
if (col[i] != col[i - 1])
nw[++sz] = col[i];
for (int i = 1; i <= sz; i++) {
dp[i] = res[nw[i]];
res[nw[i]] = (res[nw[i]] + dp[i - 1] + 1) % P;
dp[i] = (dp[i] + dp[i - 1]) % P;
}
printf("%lld\n", (dp[sz] + 1) % P);
return 0;
} | [
"identifier.change",
"variable_access.subscript.index.change",
"call.arguments.change",
"expression.operation.binary.change",
"io.output.change"
] | 906,782 | 906,783 | u543409245 | cpp |
p03096 | #include <iostream>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
int main() {
int n;
cin >> n;
int c[200005];
for (int i = 1; i <= n; i++) {
cin >> c[i];
}
ll memo[200005]{1};
int last[200005];
for (int i = 0; i <= n; i++) {
last[i] = -1;
}
int pre = -1;
for (int i = 1; i <= n; i++) {
if (i == 1) {
memo[1] = 1;
}
if (c[i] == pre) {
memo[i] = memo[i - 1];
} else {
if (last[c[i]] == -1) {
memo[i] = memo[i - 1];
} else {
memo[i] = (memo[i - 1] + memo[last[c[i]]]);
}
}
last[c[i]] = i;
pre = c[i];
}
cout << memo[n] << endl;
} | #include <iostream>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
int main() {
int n;
cin >> n;
int c[200005];
for (int i = 1; i <= n; i++) {
cin >> c[i];
}
ll memo[200005]{1};
int last[200005];
for (int i = 0; i <= 200000; i++) {
last[i] = -1;
}
int pre = -1;
for (int i = 1; i <= n; i++) {
if (i == 1) {
memo[1] = 1;
}
if (c[i] == pre) {
memo[i] = memo[i - 1];
} else {
if (last[c[i]] == -1) {
memo[i] = memo[i - 1];
} else {
memo[i] = (memo[i - 1] + memo[last[c[i]]]) % MOD;
}
}
last[c[i]] = i;
pre = c[i];
}
cout << memo[n] << endl;
} | [
"identifier.replace.remove",
"literal.replace.add",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change",
"assignment.change"
] | 906,801 | 906,802 | u681557252 | cpp |
p03096 | #include <iostream>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
int main() {
int n;
cin >> n;
int c[200005];
for (int i = 1; i <= n; i++) {
cin >> c[i];
}
ll memo[200005]{1};
int last[200005];
for (int i = 0; i <= n; i++) {
last[i] = -1;
}
int pre = -1;
for (int i = 1; i <= n; i++) {
if (i == 1) {
memo[1] = 1;
}
if (c[i] == pre) {
memo[i] = memo[i - 1];
} else {
if (last[c[i]] == -1) {
memo[i] = memo[i - 1];
} else {
memo[i] = (memo[i - 1] + memo[last[c[i]]]) % MOD;
}
}
last[c[i]] = i;
pre = c[i];
}
cout << memo[n] << endl;
} | #include <iostream>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
int main() {
int n;
cin >> n;
int c[200005];
for (int i = 1; i <= n; i++) {
cin >> c[i];
}
ll memo[200005]{1};
int last[200005];
for (int i = 0; i <= 200000; i++) {
last[i] = -1;
}
int pre = -1;
for (int i = 1; i <= n; i++) {
if (i == 1) {
memo[1] = 1;
}
if (c[i] == pre) {
memo[i] = memo[i - 1];
} else {
if (last[c[i]] == -1) {
memo[i] = memo[i - 1];
} else {
memo[i] = (memo[i - 1] + memo[last[c[i]]]) % MOD;
}
}
last[c[i]] = i;
pre = c[i];
}
cout << memo[n] << endl;
} | [
"identifier.replace.remove",
"literal.replace.add",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 906,803 | 906,802 | u681557252 | cpp |
p03096 | #include <iostream>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
int main() {
int n;
cin >> n;
int c[200001];
for (int i = 1; i <= n; i++) {
cin >> c[i];
}
ll memo[200001]{1};
int last[200001];
for (int i = 0; i <= n; i++) {
last[i] = -1;
}
int pre = -1;
for (int i = 1; i <= n; i++) {
if (i == 1) {
memo[1] = 1;
}
if (c[i] == pre) {
memo[i] = memo[i - 1];
} else {
if (last[c[i]] == -1) {
memo[i] = memo[i - 1];
} else {
memo[i] = (memo[i - 1] + memo[last[c[i]]]) % MOD;
}
}
last[c[i]] = i;
pre = c[i];
}
cout << memo[n] << endl;
} | #include <iostream>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
int main() {
int n;
cin >> n;
int c[200005];
for (int i = 1; i <= n; i++) {
cin >> c[i];
}
ll memo[200005]{1};
int last[200005];
for (int i = 0; i <= 200000; i++) {
last[i] = -1;
}
int pre = -1;
for (int i = 1; i <= n; i++) {
if (i == 1) {
memo[1] = 1;
}
if (c[i] == pre) {
memo[i] = memo[i - 1];
} else {
if (last[c[i]] == -1) {
memo[i] = memo[i - 1];
} else {
memo[i] = (memo[i - 1] + memo[last[c[i]]]) % MOD;
}
}
last[c[i]] = i;
pre = c[i];
}
cout << memo[n] << endl;
} | [
"literal.number.change",
"variable_declaration.array_dimensions.change",
"identifier.replace.remove",
"literal.replace.add",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 906,804 | 906,802 | u681557252 | cpp |
p03096 | #include <cstdio>
#include <cstring>
using namespace std;
using ll = long long;
const static int MOD = 1000000007;
int main() {
int N;
scanf("%d", &N);
int C[N];
scanf("%d", C);
int id = 0;
for (int i = 0; i < N - 1; ++i) {
int tmp;
scanf("%d", &tmp);
if (tmp != C[id])
C[++id] = tmp;
}
int last[N + 1];
memset(last, -1, sizeof last);
ll dp[N];
dp[0] = 1;
last[C[0]] = 0;
for (int i = 0; i < id; ++i) {
dp[i + 1] = dp[i];
if (last[C[i + 1]] >= 0) {
(dp[i + 1] += dp[last[C[i + 1]]]) %= MOD;
}
last[C[i + 1]] = i + 1;
}
printf("%lld\n", dp[id]);
return 0;
} | #include <cstdio>
#include <cstring>
using namespace std;
using ll = long long;
const static int MOD = 1000000007;
int main() {
int N;
scanf("%d", &N);
int C[N];
scanf("%d", C);
int id = 0;
for (int i = 0; i < N - 1; ++i) {
int tmp;
scanf("%d", &tmp);
if (tmp != C[id])
C[++id] = tmp;
}
int last[200001];
memset(last, -1, sizeof last);
ll dp[N];
dp[0] = 1;
last[C[0]] = 0;
for (int i = 0; i < id; ++i) {
dp[i + 1] = dp[i];
if (last[C[i + 1]] >= 0) {
(dp[i + 1] += dp[last[C[i + 1]]]) %= MOD;
}
last[C[i + 1]] = i + 1;
}
printf("%lld\n", dp[id]);
return 0;
} | [
"identifier.replace.remove",
"literal.replace.add",
"expression.operation.binary.change",
"expression.operation.binary.remove"
] | 906,809 | 906,810 | u642912410 | cpp |
p03096 | #include <bits/stdc++.h>
#define file(a) \
freopen(a ".in", "r", stdin); \
freopen(a ".out", "w", stdout)
using namespace std;
typedef long long ll;
long long f[200001][2]; //到i位置选还是不选的方案数
int a[200011];
const int mod = 1e9 + 7;
int sum[200011];
main() {
// file("a");
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
f[0][0] = 1;
for (register int i = 1; i <= n; i++) {
if (a[i] == a[i - 1]) {
f[i][0] = f[i - 1][0], f[i][1] = f[i - 1][1];
continue;
}
f[i][0] = (f[i - 1][1] + f[i - 1][0]) % mod;
f[i][1] = sum[a[i]];
sum[a[i]] += f[i][1] + f[i][0], sum[a[i]] %= mod;
}
cout << (f[n][1] + f[n][0]) % mod;
return 0;
}
| #include <bits/stdc++.h>
#define file(a) \
freopen(a ".in", "r", stdin); \
freopen(a ".out", "w", stdout)
using namespace std;
typedef long long ll;
long long f[200001][2]; //到i位置选还是不选的方案数
int a[200011];
const int mod = 1e9 + 7;
long long sum[200011];
main() {
// file("a");
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
f[0][0] = 1;
for (register int i = 1; i <= n; i++) {
if (a[i] == a[i - 1]) {
f[i][0] = f[i - 1][0], f[i][1] = f[i - 1][1];
continue;
}
f[i][0] = (f[i - 1][1] + f[i - 1][0]) % mod;
f[i][1] = sum[a[i]];
sum[a[i]] = f[i][1] + f[i][0], sum[a[i]] %= mod;
}
cout << (f[n][1] + f[n][0]) % mod;
return 0;
} | [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change",
"assignment.value.change"
] | 906,811 | 906,812 | u699008937 | cpp |
p03096 | #if 1
#include <algorithm>
#include <climits>
#include <cmath>
#include <functional>
#include <iostream>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define int long long
constexpr int MOD = 1000000007;
constexpr int INF = 1145141919810;
#define LOADVEC(type, name, N) \
std::vector<type> name(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
cin >> name[nnn]; \
}
#define LOADVEC2(type, name0, name1, N) \
std::vector<type> name0(N), name1(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
cin >> name0[nnn]; \
cin >> name1[nnn]; \
}
#define LOAD(type, name) \
type name; \
cin >> name;
signed main() {
ios::sync_with_stdio(false);
LOAD(int, N);
LOADVEC(int, C0, N);
std::vector<int> C;
C.reserve(N);
int last = -1;
for (int i = 0; i < N; ++i) {
if (last != C0[i])
C.push_back(C0[i]);
last = C0[i];
}
std::vector<int> res(C.size());
std::vector<int> lastColor(N, -1);
int lastColor2 = -1;
res[0] = 1;
lastColor[C[0]] = 0;
for (int i = 1; i < C.size(); ++i) {
if (lastColor[C[i]] == -1) {
res[i] = res[i - 1];
} else {
res[i] = res[i - 1] + res[lastColor[C[i]]];
res[i] %= MOD;
}
lastColor[C[i]] = i;
}
cout << res.back();
return 0;
}
#endif
| #if 1
#include <algorithm>
#include <climits>
#include <cmath>
#include <functional>
#include <iostream>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define int long long
constexpr int MOD = 1000000007;
constexpr int INF = 1145141919810;
#define LOADVEC(type, name, N) \
std::vector<type> name(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
cin >> name[nnn]; \
}
#define LOADVEC2(type, name0, name1, N) \
std::vector<type> name0(N), name1(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
cin >> name0[nnn]; \
cin >> name1[nnn]; \
}
#define LOAD(type, name) \
type name; \
cin >> name;
signed main() {
ios::sync_with_stdio(false);
LOAD(int, N);
LOADVEC(int, C0, N);
std::vector<int> C;
C.reserve(N);
int last = -1;
for (int i = 0; i < N; ++i) {
if (last != C0[i])
C.push_back(C0[i]);
last = C0[i];
}
std::vector<int> res(C.size());
std::vector<int> lastColor(300000, -1);
int lastColor2 = -1;
res[0] = 1;
lastColor[C[0]] = 0;
for (int i = 1; i < C.size(); ++i) {
if (lastColor[C[i]] == -1) {
res[i] = res[i - 1];
} else {
res[i] = res[i - 1] + res[lastColor[C[i]]];
res[i] %= MOD;
}
lastColor[C[i]] = i;
}
cout << res.back();
return 0;
}
#endif
| [
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change"
] | 906,816 | 906,817 | u154068540 | cpp |
p03096 | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PL;
const LL INF = 1e18;
const LL MOD = 1e9 + 7;
LL N, i, j;
LL cnt, ans;
LL C[200010], D[200010];
vector<LL> V[200010], Q[200010];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> N;
for (i = 0; i < N; i++) {
cin >> C[i];
if (i == 0 || C[i] != C[i - 1])
V[C[i] - 1].push_back(i);
}
for (i = 0; i < N; i++) {
for (j = 1; j < V[i].size(); j++) {
Q[V[i][j - 1]].push_back(cnt);
Q[V[i][j]].push_back(cnt++);
}
}
ans = 1;
for (i = 0; i < N; i++) {
for (j = 0; j < Q[i].size(); j++)
ans = (ans + D[Q[i][j]]) % MOD;
for (j = 0; j < Q[i].size(); j++)
D[Q[i][j]] = ans;
}
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PL;
const LL INF = 1e18;
const LL MOD = 1e9 + 7;
LL N, i, j;
LL cnt, ans;
LL C[200010], D[200010];
vector<LL> V[200010], Q[200010];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> N;
for (i = 0; i < N; i++) {
cin >> C[i];
if (i == 0 || C[i] != C[i - 1])
V[C[i] - 1].push_back(i);
}
for (i = 0; i < 200000; i++) {
for (j = 1; j < V[i].size(); j++) {
Q[V[i][j - 1]].push_back(cnt);
Q[V[i][j]].push_back(cnt++);
}
}
ans = 1;
for (i = 0; i < N; i++) {
for (j = 0; j < Q[i].size(); j++)
ans = (ans + D[Q[i][j]]) % MOD;
for (j = 0; j < Q[i].size(); j++)
D[Q[i][j]] = ans;
}
cout << ans << endl;
return 0;
}
| [
"identifier.replace.remove",
"literal.replace.add",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 906,818 | 906,819 | u079142199 | cpp |
p03096 | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#define lop(c, l) for (int c = 1; c <= (l); ++c)
#define loop(c, l) for (int c = 0; c < (l); ++c)
using namespace std;
#define int long long
const int mod = 1000000007;
int n, pre;
int arr[200001], dp[200001], cnt[200001];
inline int add(const int &a, const int &b) { return (a + b) % mod; }
signed main(signed, char **, char **) {
scanf("%lld", &n);
lop(i, n) scanf("%lld", &arr[i]);
dp[0] = 1;
lop(i, n) {
if (arr[i] != arr[i - 1]) {
dp[i] = add(dp[pre], cnt[arr[i]]);
cnt[arr[i]] = add(cnt[arr[i]], dp[i - 1]);
pre = i;
}
}
printf("%lld", dp[pre]);
exit(0);
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#define lop(c, l) for (int c = 1; c <= (l); ++c)
#define loop(c, l) for (int c = 0; c < (l); ++c)
using namespace std;
#define int long long
const int mod = 1000000007;
int n, pre;
int arr[200001], dp[200001], cnt[200001];
inline int add(const int &a, const int &b) { return (a + b) % mod; }
signed main(signed, char **, char **) {
scanf("%lld", &n);
lop(i, n) scanf("%lld", &arr[i]);
dp[0] = 1;
lop(i, n) {
if (arr[i] != arr[i - 1]) {
dp[i] = add(dp[pre], cnt[arr[i]]);
cnt[arr[i]] = add(cnt[arr[i]], dp[pre]);
pre = i;
}
}
printf("%lld", dp[pre]);
exit(0);
} | [
"assignment.value.change",
"variable_access.subscript.index.change",
"call.arguments.change",
"expression.operation.binary.change",
"expression.operation.binary.remove"
] | 906,826 | 906,827 | u388600627 | cpp |
p03096 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int N;
int A[400010];
int bef[400010];
ll bit[400010];
ll mod = 1000000007;
int tmp[400010];
void add(int i, ll x) {
i++;
while (i <= N) {
bit[i] += x;
bit[i] %= mod;
i += i & -i;
}
}
ll sum(int i) {
i++;
ll sum = 0;
while (i > 0) {
sum += bit[i];
sum %= mod;
i -= i & -i;
}
return sum;
}
int main() {
cin >> N;
for (int i = 0; i < N; i++)
cin >> A[i];
for (int i = 0; i <= N; i++)
tmp[i] = -1;
for (int i = 0; i < N; i++) {
bef[i] = tmp[A[i]];
tmp[A[i]] = i;
}
add(0, 1);
for (int i = 0; i < N; i++) {
if (bef[i] == -1 || bef[i] == i - 1)
continue;
add(i, sum(bef[i]));
}
cout << sum(N - 1) << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int N;
int A[400010];
int bef[400010];
ll bit[400010];
ll mod = 1000000007;
int tmp[200010];
void add(int i, ll x) {
i++;
while (i <= N) {
bit[i] += x;
bit[i] %= mod;
i += i & -i;
}
}
ll sum(int i) {
i++;
ll sum = 0;
while (i > 0) {
sum += bit[i];
sum %= mod;
i -= i & -i;
}
return sum;
}
int main() {
cin >> N;
for (int i = 0; i < N; i++)
cin >> A[i];
for (int i = 0; i <= 200000; i++)
tmp[i] = -1;
for (int i = 0; i < N; i++) {
bef[i] = tmp[A[i]];
tmp[A[i]] = i;
}
add(0, 1);
for (int i = 0; i < N; i++) {
if (bef[i] == -1 || bef[i] == i - 1)
continue;
add(i, sum(bef[i]));
}
cout << sum(N - 1) << endl;
return 0;
}
| [
"literal.number.change",
"variable_declaration.array_dimensions.change",
"identifier.replace.remove",
"literal.replace.add",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 906,828 | 906,829 | u205655980 | cpp |
p03096 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int N;
int A[400010];
int bef[400010];
ll bit[200010];
ll mod = 100000007;
int tmp[400010];
void add(int i, ll x) {
i++;
while (i <= N) {
bit[i] += x;
bit[i] %= mod;
i += i & -i;
}
}
ll sum(int i) {
i++;
ll sum = 0;
while (i > 0) {
sum += bit[i];
sum %= mod;
i -= i & -i;
}
return sum;
}
int main() {
cin >> N;
for (int i = 0; i < N; i++)
cin >> A[i];
for (int i = 0; i <= N; i++)
tmp[i] = -1;
for (int i = 0; i < N; i++) {
bef[i] = tmp[A[i]];
tmp[A[i]] = i;
}
add(0, 1);
for (int i = 0; i < N; i++) {
if (bef[i] == -1 || bef[i] == i - 1)
continue;
add(i, sum(bef[i]));
}
cout << sum(N - 1) << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int N;
int A[400010];
int bef[400010];
ll bit[400010];
ll mod = 1000000007;
int tmp[200010];
void add(int i, ll x) {
i++;
while (i <= N) {
bit[i] += x;
bit[i] %= mod;
i += i & -i;
}
}
ll sum(int i) {
i++;
ll sum = 0;
while (i > 0) {
sum += bit[i];
sum %= mod;
i -= i & -i;
}
return sum;
}
int main() {
cin >> N;
for (int i = 0; i < N; i++)
cin >> A[i];
for (int i = 0; i <= 200000; i++)
tmp[i] = -1;
for (int i = 0; i < N; i++) {
bef[i] = tmp[A[i]];
tmp[A[i]] = i;
}
add(0, 1);
for (int i = 0; i < N; i++) {
if (bef[i] == -1 || bef[i] == i - 1)
continue;
add(i, sum(bef[i]));
}
cout << sum(N - 1) << endl;
return 0;
}
| [
"literal.number.change",
"variable_declaration.array_dimensions.change",
"variable_declaration.value.change",
"identifier.replace.remove",
"literal.replace.add",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 906,830 | 906,829 | u205655980 | cpp |
p03096 | #include "bits/stdc++.h"
using namespace std;
using ll = long long;
using vll = vector<ll>;
using pl4 = pair<ll, ll>;
using str = string;
using vpl4 = vector<pair<ll, ll>>;
#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define llin(x) \
ll(x); \
cin >> (x);
#define stin(x) \
str(x); \
cin >> (x);
#define vllin(x, n) \
vll(x)(n); \
FOR(i, 0, n - 1) { cin >> (x)[i]; }
#define vllin2(a, b, n) \
vll(a)(n); \
vll(b)(n); \
FOR(i, 0, n - 1) { cin >> (a)[i] >> b[i]; }
#define vpl4in(x, n) \
vpl4(x)((n), mp(0, 0)); \
FOR(i, 0, n - 1) { cin >> x[i].fi >> x[i].se; }
#define FOR(i, a, b) for (ll i = a; i <= b; i++)
#define rFOR(i, b, a) for (ll i = a; i >= b; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout << (x);
#define sal(x) cout << (x) << endl;
#define sas cout << (' ');
#define sayR(x) cout << fixed << setprecision(10) << (x);
#define salR(x) cout << fixed << setprecision(10) << (x) << endl;
#define yn(a) cout << ((a) ? "yes" : "no") << endl;
#define Yn(a) cout << ((a) ? "Yes" : "No") << endl;
#define YN(a) cout << ((a) ? "YES" : "NO") << endl;
#define Imp(a) cout << ((a) ? "Possible" : "Impossible") << endl;
#define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << endl;
#define pow(a, b) ll(pow(a, b))
ll MOD = 1000000007;
signed main() {
llin(n);
vllin(c, n);
vll m(n, -1);
vll l(n, -1);
m[0] = 1;
l[c[0]] = 0;
FOR(d, 1, n - 1) {
if (c[d] == c[d - 1]) {
m[d] = m[d - 1];
} else {
if (l[c[d]] == -1) {
m[d] = m[d - 1];
} else {
m[d] = (m[d - 1] + m[l[c[d]]]) % MOD;
}
}
l[c[d]] = d;
}
sal(m[n - 1]);
} | #include "bits/stdc++.h"
using namespace std;
using ll = long long;
using vll = vector<ll>;
using pl4 = pair<ll, ll>;
using str = string;
using vpl4 = vector<pair<ll, ll>>;
#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define llin(x) \
ll(x); \
cin >> (x);
#define stin(x) \
str(x); \
cin >> (x);
#define vllin(x, n) \
vll(x)(n); \
FOR(i, 0, n - 1) { cin >> (x)[i]; }
#define vllin2(a, b, n) \
vll(a)(n); \
vll(b)(n); \
FOR(i, 0, n - 1) { cin >> (a)[i] >> b[i]; }
#define vpl4in(x, n) \
vpl4(x)((n), mp(0, 0)); \
FOR(i, 0, n - 1) { cin >> x[i].fi >> x[i].se; }
#define FOR(i, a, b) for (ll i = a; i <= b; i++)
#define rFOR(i, b, a) for (ll i = a; i >= b; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout << (x);
#define sal(x) cout << (x) << endl;
#define sas cout << (' ');
#define sayR(x) cout << fixed << setprecision(10) << (x);
#define salR(x) cout << fixed << setprecision(10) << (x) << endl;
#define yn(a) cout << ((a) ? "yes" : "no") << endl;
#define Yn(a) cout << ((a) ? "Yes" : "No") << endl;
#define YN(a) cout << ((a) ? "YES" : "NO") << endl;
#define Imp(a) cout << ((a) ? "Possible" : "Impossible") << endl;
#define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << endl;
#define pow(a, b) ll(pow(a, b))
ll MOD = 1000000007;
signed main() {
llin(n);
vllin(c, n);
vll m(n, -1);
vll l(200005, -1);
m[0] = 1;
l[c[0]] = 0;
FOR(d, 1, n - 1) {
if (c[d] == c[d - 1]) {
m[d] = m[d - 1];
} else {
if (l[c[d]] == -1) {
m[d] = m[d - 1];
} else {
m[d] = (m[d - 1] + m[l[c[d]]]) % MOD;
}
}
l[c[d]] = d;
}
sal(m[n - 1]);
} | [
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change"
] | 906,837 | 906,838 | u614421689 | cpp |
p03096 | #include <iostream>
#include <vector>
using namespace std;
const int mod = int(1e9) + 7;
int main() {
int n;
cin >> n;
vector<int> c(1);
cin >> c[0];
for (int i = 1; i < n; i++) {
int tmp;
cin >> tmp;
if (tmp != c[i - 1])
c.push_back(tmp);
}
n = c.size();
vector<long> cn(200010, 0);
vector<long> dp(n, 0);
dp[0] = 1;
cn[c[0]] = dp[0];
for (int i = 1; i < n; i++) {
cn[c[i]] = dp[i] = (dp[i - 1] + cn[c[i]]) % mod;
}
cout << dp[n - 1];
return 0;
} | #include <iostream>
#include <vector>
using namespace std;
const int mod = int(1e9) + 7;
int main() {
int n;
cin >> n;
vector<int> c(1);
cin >> c[0];
for (int i = 1; i < n; i++) {
int tmp;
cin >> tmp;
if (tmp != c[c.size() - 1])
c.push_back(tmp);
}
n = c.size();
vector<long> cn(200010, 0);
vector<long> dp(n, 0);
dp[0] = 1;
cn[c[0]] = dp[0];
for (int i = 1; i < n; i++) {
cn[c[i]] = dp[i] = (dp[i - 1] + cn[c[i]]) % mod;
}
cout << dp[n - 1];
return 0;
} | [
"variable_access.subscript.index.change",
"control_flow.branch.if.condition.change",
"control_flow.loop.for.condition.change",
"call.add"
] | 906,839 | 906,840 | u809153881 | cpp |
p03096 | #include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mk make_pair
#define rint register int
using namespace std;
const int mod = 1e9 + 7;
inline int read() {
int w = 1, s = 0;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-')
w = -1;
ch = getchar();
}
while (isdigit(ch)) {
s = s * 10 + ch - '0';
ch = getchar();
}
return w * s;
}
int f[200010], n, C[200010], Sum[200100], Seq[200010], cnt, Pre[200010],
hd[200010];
// inline int add(int a,int b){a+=b;return a>=mod?a-mod:a;}
int S[200010];
inline int lowbit(int x) { return x & (-x); }
inline void add(int pos, int dd) {
while (pos <= n + 1)
S[pos] += dd, S[pos] %= mod, pos += lowbit(pos);
}
inline int Qry(int pos) {
if (pos < 0)
return 0;
int res = 0;
while (pos)
res += S[pos], pos -= lowbit(pos), res %= mod;
return res;
}
inline int Add(int a, int b) {
a += b;
return a >= mod ? a - mod : a;
}
int main() {
n = read();
for (rint i = 1; i <= n; ++i)
C[i] = read();
for (rint i = 1; i <= n; ++i)
if (C[i] != Seq[cnt])
Seq[++cnt] = C[i];
n = cnt;
for (rint i = 1; i <= n; ++i)
Pre[i] = hd[C[i]], hd[C[i]] = i; // cout<<1<<"\n";
f[0] = 1;
add(1, 1);
for (rint i = 1; i <= n; ++i) {
// cout<<Pre[i]<<"\n";
// f[i]=Add(f[i],f[i-1]);
// if(Pre[i]==0) Pre[i]++;
if (Pre[i] == 0)
continue;
f[i] = Add(f[i], Qry(Pre[i] + 1));
// if(Pre[i]>1)
add(i + 1, f[i]);
// cout<<Pre[i]<<"\n";
// cout<<f[i]<<" f\n";
}
int res = 0;
for (rint i = 0; i <= n; ++i) {
res += f[i];
res %= mod;
}
cout << res;
return 0;
}
| #include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mk make_pair
#define rint register int
using namespace std;
const int mod = 1e9 + 7;
inline int read() {
int w = 1, s = 0;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-')
w = -1;
ch = getchar();
}
while (isdigit(ch)) {
s = s * 10 + ch - '0';
ch = getchar();
}
return w * s;
}
int f[200010], n, C[200010], Sum[200100], Seq[200010], cnt, Pre[200010],
hd[200010];
// inline int add(int a,int b){a+=b;return a>=mod?a-mod:a;}
int S[200010];
inline int lowbit(int x) { return x & (-x); }
inline void add(int pos, int dd) {
while (pos <= (n + 1))
S[pos] += dd, S[pos] %= mod, pos += lowbit(pos);
}
inline int Qry(int pos) {
if (pos < 0)
return 0;
int res = 0;
while (pos)
res += S[pos], pos -= lowbit(pos), res %= mod;
return res;
}
inline int Add(int a, int b) {
a += b;
return a >= mod ? a - mod : a;
}
int main() {
n = read();
for (rint i = 1; i <= n; ++i)
C[i] = read();
for (rint i = 1; i <= n; ++i)
if (C[i] != Seq[cnt])
Seq[++cnt] = C[i];
n = cnt;
for (rint i = 1; i <= n; ++i)
Pre[i] = hd[Seq[i]], hd[Seq[i]] = i; // cout<<1<<"\n";
f[0] = 1;
add(1, 1);
for (rint i = 1; i <= n; ++i) {
// cout<<Pre[i]<<"\n";
// f[i]=Add(f[i],f[i-1]);
// if(Pre[i]==0) Pre[i]++;
if (Pre[i] == 0)
continue;
f[i] = Add(f[i], Qry(Pre[i] + 1));
// if(Pre[i]>1)
add(i + 1, f[i]);
// cout<<Pre[i]<<"\n";
// cout<<f[i]<<" f\n";
}
int res = 0;
for (rint i = 0; i <= n; ++i) {
res += f[i];
res %= mod;
}
cout << res % mod;
return 0;
}
| [
"control_flow.loop.condition.change",
"assignment.value.change",
"identifier.change",
"variable_access.subscript.index.change",
"assignment.variable.change"
] | 906,857 | 906,858 | u574380866 | cpp |
p03096 | #include <algorithm>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
const int INF = 0x3f3f3f3f, MOD = 1000000007;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*-----------------------------------------*/
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
// freopen("input.txt", "r", stdin);
int n;
cin >> n;
vector<long long> memo(n + 1, 0);
vector<int> c;
int mae = -1;
REP(i, n) {
int cc;
cin >> cc;
if (mae != cc) {
c.emplace_back(cc);
mae = cc;
}
}
n = c.size();
long long pre = 1;
REP(i, n) {
(memo[c[i]] += pre) %= MOD;
pre = memo[c[i]];
}
cout << pre << '\n';
return 0;
}
| #include <algorithm>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
const int INF = 0x3f3f3f3f, MOD = 1000000007;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*-----------------------------------------*/
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
// freopen("input.txt", "r", stdin);
int n;
cin >> n;
vector<long long> memo(200001, 0);
vector<int> c;
int mae = -1;
REP(i, n) {
int cc;
cin >> cc;
if (mae != cc) {
c.emplace_back(cc);
mae = cc;
}
}
n = c.size();
long long pre = 1;
REP(i, n) {
(memo[c[i]] += pre) %= MOD;
pre = memo[c[i]];
}
cout << pre << '\n';
return 0;
}
| [
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change",
"expression.operation.binary.change",
"expression.operation.binary.remove"
] | 906,877 | 906,878 | u219786796 | cpp |
p03096 | #include <bits/stdc++.h>
using namespace std;
//#define DEBUG_MODE
#define endl '\n'
#ifdef DEBUG_MODE
#define DEBUG(X) debug_func(X, #X)
#define DEBUG_ENDL endl << flush
#define DEBUG_SEPARATOR_LINE cout << "=================\n"
#else
#define DEBUG(X) 0
#define DEBUG_ENDL 0
#define DEBUG_SEPARATOR_LINE 0
#endif
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
#define DEBUG_ENDL_S(S) ((S).size() ? "\n" : "") << flush;
template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;
template <typename T> const T &var_min(const T &t) { return t; }
template <typename T> const T &var_max(const T &t) { return t; }
template <typename Head, typename... Tail>
const Head &var_min(const Head &head, const Tail &...tail) {
return min(head, var_min(tail...));
}
template <typename Head, typename... Tail>
const Head &var_max(const Head &head, const Tail &...tail) {
return max(head, var_max(tail...));
}
template <typename T, typename... Tail> void chmin(T &t, const Tail &...tail) {
t = var_min(t, tail...);
}
template <typename T, typename... Tail> void chmax(T &t, const Tail &...tail) {
t = var_max(t, tail...);
}
void debug_func_preffix(const string &s) {
if (s.size())
cout << s << " = ";
}
template <typename T> void debug_func(const T &t, const string &s = "") {
debug_func_preffix(s);
cout << t << DEBUG_ENDL_S(s);
}
template <typename T, typename U>
void debug_func(const P<T, U> &p, const string &s = "") {
debug_func_preffix(s);
cout << "(";
debug_func(p.first);
cout << ", ";
debug_func(p.second);
cout << ")" << DEBUG_ENDL_S(s);
}
template <typename T> void debug_func(const V<T> &v, const string &s = "") {
for (ll i = 0; i < v.size(); i++) {
string t = s + "[" + to_string(i) + "]";
debug_func(v[i], t);
}
}
void init_io() {
cin.tie(0);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(30);
}
const ll MOD = 1e9 + 7;
int main() {
init_io();
ll N;
cin >> N;
V<ll> dp(N + 1);
ll pre = -1;
V<ll> prec(N, -1);
dp[0] = 1;
for (ll i = 0; i < N; i++) {
ll e;
cin >> e;
e--;
if (e == pre) {
dp[i + 1] = dp[i];
continue;
}
if (prec[e] == -1) {
pre = e;
prec[e] = i;
dp[i + 1] = dp[i];
continue;
}
DEBUG(i);
DEBUG(e + 1);
DEBUG(prec[e]);
DEBUG(dp[prec[e]]);
dp[i + 1] = (dp[prec[e] + 1] + dp[i]) % MOD;
prec[e] = i;
pre = e;
}
DEBUG(dp);
cout << dp[N] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
//#define DEBUG_MODE
#define endl '\n'
#ifdef DEBUG_MODE
#define DEBUG(X) debug_func(X, #X)
#define DEBUG_ENDL endl << flush
#define DEBUG_SEPARATOR_LINE cout << "=================\n"
#else
#define DEBUG(X) 0
#define DEBUG_ENDL 0
#define DEBUG_SEPARATOR_LINE 0
#endif
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
#define DEBUG_ENDL_S(S) ((S).size() ? "\n" : "") << flush;
template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;
template <typename T> const T &var_min(const T &t) { return t; }
template <typename T> const T &var_max(const T &t) { return t; }
template <typename Head, typename... Tail>
const Head &var_min(const Head &head, const Tail &...tail) {
return min(head, var_min(tail...));
}
template <typename Head, typename... Tail>
const Head &var_max(const Head &head, const Tail &...tail) {
return max(head, var_max(tail...));
}
template <typename T, typename... Tail> void chmin(T &t, const Tail &...tail) {
t = var_min(t, tail...);
}
template <typename T, typename... Tail> void chmax(T &t, const Tail &...tail) {
t = var_max(t, tail...);
}
void debug_func_preffix(const string &s) {
if (s.size())
cout << s << " = ";
}
template <typename T> void debug_func(const T &t, const string &s = "") {
debug_func_preffix(s);
cout << t << DEBUG_ENDL_S(s);
}
template <typename T, typename U>
void debug_func(const P<T, U> &p, const string &s = "") {
debug_func_preffix(s);
cout << "(";
debug_func(p.first);
cout << ", ";
debug_func(p.second);
cout << ")" << DEBUG_ENDL_S(s);
}
template <typename T> void debug_func(const V<T> &v, const string &s = "") {
for (ll i = 0; i < v.size(); i++) {
string t = s + "[" + to_string(i) + "]";
debug_func(v[i], t);
}
}
void init_io() {
cin.tie(0);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(30);
}
const ll MOD = 1e9 + 7;
int main() {
init_io();
ll N;
cin >> N;
V<ll> dp(N + 1);
ll pre = -1;
V<ll> prec(2e5 + 10, -1);
dp[0] = 1;
for (ll i = 0; i < N; i++) {
ll e;
cin >> e;
e--;
if (e == pre) {
dp[i + 1] = dp[i];
continue;
}
if (prec[e] == -1) {
pre = e;
prec[e] = i;
dp[i + 1] = dp[i];
continue;
}
DEBUG(i);
DEBUG(e + 1);
DEBUG(prec[e]);
DEBUG(dp[prec[e]]);
dp[i + 1] = (dp[prec[e] + 1] + dp[i]) % MOD;
prec[e] = i;
pre = e;
}
DEBUG(dp);
cout << dp[N] << endl;
return 0;
}
| [
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change"
] | 906,886 | 906,887 | u216962796 | cpp |
p03096 | #define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;
typedef pair<long long int, long long int> P;
long long int INF = 1e18;
long long int MOD = 1e9 + 7;
long long int DP[210000] = {};
long long int col[210000] = {};
int main() {
int N;
cin >> N;
DP[0] = 1;
for (int i = 1; i <= N; i++) {
int C;
cin >> C;
DP[i] = DP[i - 1];
if (col[C] != 0 && col[C] != i - 1) {
DP[i] += DP[col[C]];
}
DP[i] %= N;
col[C] = i;
}
cout << DP[N] << endl;
return 0;
} | #define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;
typedef pair<long long int, long long int> P;
long long int INF = 1e18;
long long int MOD = 1e9 + 7;
long long int DP[210000] = {};
long long int col[210000] = {};
int main() {
int N;
cin >> N;
DP[0] = 1;
for (int i = 1; i <= N; i++) {
int C;
cin >> C;
DP[i] = DP[i - 1];
if (col[C] != 0 && col[C] != i - 1) {
DP[i] += DP[col[C]];
}
DP[i] %= MOD;
col[C] = i;
}
cout << DP[N] << endl;
return 0;
} | [
"assignment.value.change",
"identifier.change"
] | 906,891 | 906,892 | u997521090 | cpp |
p03096 | #include <bits/stdc++.h>
using namespace std;
#define REP(i, m) for (int i = 0; i < m; i++)
#define FOR(i, n, m) for (int i = n; i < m; i++)
#define INF 1000000007
#define INFL (1LL << 60)
#define MOD 998244353
#define ALL(v) v.begin(), v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>
bool comp(P p1, P p2) { return p1.second < p2.second; }
int main() {
int n;
cin >> n;
vector<int> a[200001];
REP(i, n) {
int x;
cin >> x;
a[x].pb(i);
}
vector<P> f;
REP(i, 200001) {
if (a[i].size() >= 2) {
REP(j, a[i].size() - 1) {
if (a[i][j + 1] - a[i][j] > 1)
f.pb({a[i][j], a[i][j + 1]});
}
}
}
sort(ALL(f), comp);
int fs = f.size();
ll dp[fs + 1];
dp[0] = 1;
REP(i, fs) {
if (f[i].first < f[0].second)
dp[i + 1] = (dp[i] + 1) % INF;
else {
int ft = 0, l = fs;
while (l - ft > 1) {
int m = (l + ft) / 2;
if (f[i].first > f[m].second)
ft = m;
else
l = m;
}
dp[i + 1] = (dp[i] + dp[ft + 1]) % INF;
}
}
cout << dp[fs] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define REP(i, m) for (int i = 0; i < m; i++)
#define FOR(i, n, m) for (int i = n; i < m; i++)
#define INF 1000000007
#define INFL (1LL << 60)
#define MOD 998244353
#define ALL(v) v.begin(), v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>
bool comp(P p1, P p2) { return p1.second < p2.second; }
int main() {
int n;
cin >> n;
vector<int> a[200001];
REP(i, n) {
int x;
cin >> x;
a[x].pb(i);
}
vector<P> f;
REP(i, 200001) {
if (a[i].size() >= 2) {
REP(j, a[i].size() - 1) {
if (a[i][j + 1] - a[i][j] > 1)
f.pb({a[i][j], a[i][j + 1]});
}
}
}
sort(ALL(f), comp);
int fs = f.size();
ll dp[fs + 1];
dp[0] = 1;
REP(i, fs) {
if (f[i].first < f[0].second)
dp[i + 1] = (dp[i] + 1) % INF;
else {
int ft = 0, l = fs;
while (l - ft > 1) {
int m = (l + ft) / 2;
if (f[i].first >= f[m].second)
ft = m;
else
l = m;
}
dp[i + 1] = (dp[i] + dp[ft + 1]) % INF;
}
}
cout << dp[fs] << endl;
return 0;
}
| [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 906,897 | 906,898 | u773548422 | cpp |
p03096 | #include <algorithm>
#include <iostream>
using namespace std;
const int z = 1e9 + 7;
const int C = 2e5;
int main() {
int n;
cin >> n;
int last[C];
fill(last, last + C, -1);
int dp[n + 1];
dp[0] = 1;
for (int i = 1; i <= n; i++) {
int c;
cin >> c;
c--;
dp[i] = dp[i - 1];
if (last[c] != -1 && last[c] != i - 1) {
dp[i] += dp[last[c] - 1];
if (dp[i] >= z) {
dp[i] -= z;
}
}
last[c] = i;
}
cout << dp[n] << endl;
return 0;
}
| #include <algorithm>
#include <iostream>
using namespace std;
const int z = 1e9 + 7;
const int C = 2e5;
int main() {
int n;
cin >> n;
int last[C];
fill(last, last + C, -1);
int dp[n + 1];
dp[0] = 1;
for (int i = 1; i <= n; i++) {
int c;
cin >> c;
c--;
dp[i] = dp[i - 1];
if (last[c] != -1 && last[c] != i - 1) {
dp[i] += dp[last[c]];
if (dp[i] >= z) {
dp[i] -= z;
}
}
last[c] = i;
}
cout << dp[n] << endl;
return 0;
}
| [
"expression.operation.binary.remove"
] | 906,908 | 906,909 | u587665681 | cpp |
p03096 | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define repl(i, s, n) for (int i = s; i <= n; ++i)
#define rer(i, l, u) for (int(i) = (int)(l); (i) <= (int)(u); ++(i))
#define reu(i, l, u) for (int(i) = (int)(l); (i) < (int)(u); ++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r, v) auto r = (v)
#else
#define aut(r, v) __typeof(v) r = (v)
#endif
#define each(it, o) for (aut(it, (o).begin()); it != (o).end(); ++it)
#define ktya(x) sort(all(x))
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x, y) make_pair((x), (y))
#define mset(m, v) memset(m, v, sizeof(m))
#define INF 1000000007
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a, b) (a > b ? b : a)
#define maxd(a, b) (a > b ? a : b)
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;
typedef long long ll;
typedef pair<int, ll> pill;
typedef pair<ll, int> plli;
typedef pair<double, int> pdi;
template <typename T, typename U> inline void amin(T &x, U y) {
if (y < x)
x = y;
}
template <typename T, typename U> inline void amax(T &x, U y) {
if (x < y)
x = y;
}
typedef complex<double> P;
ll MOD = 1000000007;
// ll MOD=998244353;
typedef ll Weight;
struct Edge {
int src, dst;
Weight weight;
};
bool operator<(const Edge &e, const Edge &f) {
return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
e.src != f.src ? e.src < f.src
: e.dst < f.dst;
}
typedef vector<Edge> Edges;
int N;
int C[214514];
int mem[214514];
ll dp[214514] = {0};
int main() {
cin >> N;
rep(i, N + 1) mem[i] = -1;
dp[0] = 1;
rep(i, N) {
int x;
cin >> x;
dp[i + 1] = dp[i];
int bef = mem[x];
if (bef != -1 && bef != i - 1) {
dp[i + 1] += dp[bef + 1];
dp[i + 1] %= MOD;
}
mem[x] = i;
}
cout << dp[N] << endl;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define repl(i, s, n) for (int i = s; i <= n; ++i)
#define rer(i, l, u) for (int(i) = (int)(l); (i) <= (int)(u); ++(i))
#define reu(i, l, u) for (int(i) = (int)(l); (i) < (int)(u); ++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r, v) auto r = (v)
#else
#define aut(r, v) __typeof(v) r = (v)
#endif
#define each(it, o) for (aut(it, (o).begin()); it != (o).end(); ++it)
#define ktya(x) sort(all(x))
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x, y) make_pair((x), (y))
#define mset(m, v) memset(m, v, sizeof(m))
#define INF 1000000007
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a, b) (a > b ? b : a)
#define maxd(a, b) (a > b ? a : b)
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;
typedef long long ll;
typedef pair<int, ll> pill;
typedef pair<ll, int> plli;
typedef pair<double, int> pdi;
template <typename T, typename U> inline void amin(T &x, U y) {
if (y < x)
x = y;
}
template <typename T, typename U> inline void amax(T &x, U y) {
if (x < y)
x = y;
}
typedef complex<double> P;
ll MOD = 1000000007;
// ll MOD=998244353;
typedef ll Weight;
struct Edge {
int src, dst;
Weight weight;
};
bool operator<(const Edge &e, const Edge &f) {
return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
e.src != f.src ? e.src < f.src
: e.dst < f.dst;
}
typedef vector<Edge> Edges;
int N;
int C[214514];
int mem[214514];
ll dp[214514] = {0};
int main() {
cin >> N;
rep(i, 214514) mem[i] = -1;
dp[0] = 1;
rep(i, N) {
int x;
cin >> x;
dp[i + 1] = dp[i];
int bef = mem[x];
if (bef != -1 && bef != i - 1) {
dp[i + 1] += dp[bef + 1];
dp[i + 1] %= MOD;
}
mem[x] = i;
}
cout << dp[N] << endl;
} | [
"assignment.variable.change",
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change",
"expression.operation.binary.change",
"expression.operation.binary.remove"
] | 906,910 | 906,911 | u703999673 | cpp |
p03096 | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define repl(i, s, n) for (int i = s; i <= n; ++i)
#define rer(i, l, u) for (int(i) = (int)(l); (i) <= (int)(u); ++(i))
#define reu(i, l, u) for (int(i) = (int)(l); (i) < (int)(u); ++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r, v) auto r = (v)
#else
#define aut(r, v) __typeof(v) r = (v)
#endif
#define each(it, o) for (aut(it, (o).begin()); it != (o).end(); ++it)
#define ktya(x) sort(all(x))
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x, y) make_pair((x), (y))
#define mset(m, v) memset(m, v, sizeof(m))
#define INF 1000000007
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a, b) (a > b ? b : a)
#define maxd(a, b) (a > b ? a : b)
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;
typedef long long ll;
typedef pair<int, ll> pill;
typedef pair<ll, int> plli;
typedef pair<double, int> pdi;
template <typename T, typename U> inline void amin(T &x, U y) {
if (y < x)
x = y;
}
template <typename T, typename U> inline void amax(T &x, U y) {
if (x < y)
x = y;
}
typedef complex<double> P;
ll MOD = 1000000007;
// ll MOD=998244353;
typedef ll Weight;
struct Edge {
int src, dst;
Weight weight;
};
bool operator<(const Edge &e, const Edge &f) {
return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
e.src != f.src ? e.src < f.src
: e.dst < f.dst;
}
typedef vector<Edge> Edges;
int N;
int C[214514];
int mem[214514];
ll dp[214514] = {0};
int main() {
cin >> N;
rep(i, N) mem[i] = -1;
dp[0] = 1;
rep(i, N) {
int x;
cin >> x;
dp[i + 1] = dp[i];
int bef = mem[x];
if (bef != -1 && bef != i - 1) {
dp[i + 1] += dp[mem[x] + 1];
dp[i + 1] %= MOD;
}
mem[x] = i;
}
cout << dp[N] << endl;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define repl(i, s, n) for (int i = s; i <= n; ++i)
#define rer(i, l, u) for (int(i) = (int)(l); (i) <= (int)(u); ++(i))
#define reu(i, l, u) for (int(i) = (int)(l); (i) < (int)(u); ++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r, v) auto r = (v)
#else
#define aut(r, v) __typeof(v) r = (v)
#endif
#define each(it, o) for (aut(it, (o).begin()); it != (o).end(); ++it)
#define ktya(x) sort(all(x))
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x, y) make_pair((x), (y))
#define mset(m, v) memset(m, v, sizeof(m))
#define INF 1000000007
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a, b) (a > b ? b : a)
#define maxd(a, b) (a > b ? a : b)
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;
typedef long long ll;
typedef pair<int, ll> pill;
typedef pair<ll, int> plli;
typedef pair<double, int> pdi;
template <typename T, typename U> inline void amin(T &x, U y) {
if (y < x)
x = y;
}
template <typename T, typename U> inline void amax(T &x, U y) {
if (x < y)
x = y;
}
typedef complex<double> P;
ll MOD = 1000000007;
// ll MOD=998244353;
typedef ll Weight;
struct Edge {
int src, dst;
Weight weight;
};
bool operator<(const Edge &e, const Edge &f) {
return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
e.src != f.src ? e.src < f.src
: e.dst < f.dst;
}
typedef vector<Edge> Edges;
int N;
int C[214514];
int mem[214514];
ll dp[214514] = {0};
int main() {
cin >> N;
rep(i, 214514) mem[i] = -1;
dp[0] = 1;
rep(i, N) {
int x;
cin >> x;
dp[i + 1] = dp[i];
int bef = mem[x];
if (bef != -1 && bef != i - 1) {
dp[i + 1] += dp[bef + 1];
dp[i + 1] %= MOD;
}
mem[x] = i;
}
cout << dp[N] << endl;
} | [
"assignment.variable.change",
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change",
"assignment.value.change",
"variable_access.subscript.index.change",
"expression.operation.binary.change"
] | 906,912 | 906,911 | u703999673 | cpp |
p03096 | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
int main() {
int N;
cin >> N;
vector<int> C(N);
rep(i, N) cin >> C[i];
vector<int> dp(N + 1);
map<int, int> d;
dp[0] = 1;
rep(i, N) {
dp[i + 1] = dp[i];
if (i > 1 && C[i - 1] == C[i]) {
continue;
}
if (d[C[i]] > 0) {
dp[i + 1] += dp[d[C[i]]];
}
d[C[i]] = i + 1;
dp[i + 1] %= MOD;
}
cout << dp[N] << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
int main() {
int N;
cin >> N;
vector<int> C(N);
rep(i, N) cin >> C[i];
vector<int> dp(N + 1);
map<int, int> d;
dp[0] = 1;
rep(i, N) {
dp[i + 1] = dp[i];
if (i > 0 && C[i - 1] == C[i]) {
continue;
}
if (d[C[i]] > 0) {
dp[i + 1] += dp[d[C[i]]];
}
d[C[i]] = i + 1;
dp[i + 1] %= MOD;
}
cout << dp[N] << endl;
return 0;
}
| [
"literal.number.change",
"control_flow.branch.if.condition.change"
] | 906,923 | 906,924 | u814781830 | cpp |
p03096 |
//#pragma GCC target("avx2")
#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif
void d_err() { cerr << endl; }
template <typename H, typename... T> void d_err(H h, T... t) {
cerr << h << " ";
d_err(t...);
}
template <typename T> void print(T x) { cout << x << "\n"; }
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pin;
ll INF = 1e16;
int inf = 1e9;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
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 {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= 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, mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(20);
int n;
cin >> n;
vector<int> a(n);
REP(i, n) cin >> a[i];
vector<int> ca;
int prev = -1;
REP(i, n) {
if (prev == a[i])
continue;
ca.pb(a[i]);
prev = a[i];
}
vector<int> last(n + 1, -1);
vector<mint> dp(ca.size(), 0);
dp[0] = 1;
last[ca[0]] = 0;
FOR(i, 1, ca.size()) {
if (last[ca[i]] > -1)
dp[i] += dp[last[ca[i]]];
last[ca[i]] = i;
dp[i] += dp[i - 1];
}
print(dp[ca.size() - 1]);
}
|
//#pragma GCC target("avx2")
#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif
void d_err() { cerr << endl; }
template <typename H, typename... T> void d_err(H h, T... t) {
cerr << h << " ";
d_err(t...);
}
template <typename T> void print(T x) { cout << x << "\n"; }
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pin;
ll INF = 1e16;
int inf = 1e9;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
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 {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= 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, mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(20);
int n;
cin >> n;
vector<int> a(n);
REP(i, n) cin >> a[i];
vector<int> ca;
int prev = -1;
REP(i, n) {
if (prev == a[i])
continue;
ca.pb(a[i]);
prev = a[i];
}
vector<int> last(2e5 + 5, -1);
vector<mint> dp(ca.size(), 0);
dp[0] = 1;
last[ca[0]] = 0;
FOR(i, 1, ca.size()) {
if (last[ca[i]] > -1)
dp[i] += dp[last[ca[i]]];
last[ca[i]] = i;
dp[i] += dp[i - 1];
}
print(dp[ca.size() - 1]);
}
| [
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change",
"expression.operation.binary.change",
"literal.number.change"
] | 906,925 | 906,926 | u089177147 | cpp |
p03096 |
//#pragma GCC target("avx2")
#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif
void d_err() { cerr << endl; }
template <typename H, typename... T> void d_err(H h, T... t) {
cerr << h << " ";
d_err(t...);
}
template <typename T> void print(T x) { cout << x << "\n"; }
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pin;
ll INF = 1e16;
int inf = 1e9;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
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 {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= 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, mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(20);
int n;
cin >> n;
vector<int> a(n);
REP(i, n) cin >> a[i];
vector<int> ca;
int prev = -1;
REP(i, n) {
if (prev == a[i])
continue;
ca.pb(a[i]);
prev = a[i];
}
vector<int> last(n, -1);
vector<mint> dp(ca.size(), 0);
dp[0] = 1;
last[ca[0]] = 0;
FOR(i, 1, ca.size()) {
if (last[ca[i]] > -1)
dp[i] += dp[last[ca[i]]];
last[ca[i]] = i;
dp[i] += dp[i - 1];
}
print(dp[ca.size() - 1]);
}
|
//#pragma GCC target("avx2")
#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif
void d_err() { cerr << endl; }
template <typename H, typename... T> void d_err(H h, T... t) {
cerr << h << " ";
d_err(t...);
}
template <typename T> void print(T x) { cout << x << "\n"; }
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pin;
ll INF = 1e16;
int inf = 1e9;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
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 {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= 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, mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(20);
int n;
cin >> n;
vector<int> a(n);
REP(i, n) cin >> a[i];
vector<int> ca;
int prev = -1;
REP(i, n) {
if (prev == a[i])
continue;
ca.pb(a[i]);
prev = a[i];
}
vector<int> last(2e5 + 5, -1);
vector<mint> dp(ca.size(), 0);
dp[0] = 1;
last[ca[0]] = 0;
FOR(i, 1, ca.size()) {
if (last[ca[i]] > -1)
dp[i] += dp[last[ca[i]]];
last[ca[i]] = i;
dp[i] += dp[i - 1];
}
print(dp[ca.size() - 1]);
}
| [
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change"
] | 906,927 | 906,926 | u089177147 | cpp |
p03096 | #include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const int mod = 1000000007;
struct mint {
ll x;
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 {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
mint inv() const { return pow(mod - 2); }
mint &operator/=(const mint a) { return (*this) *= a.inv(); }
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
bool operator==(const mint a) { return x == a.x; }
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<int> a(n);
rep(i, n) {
cin >> a[i];
--a[i];
}
vector<mint> ans(n + 1, 0);
ans[a[0]] = 1;
rep(i, n - 1) {
if (a[i] != a[i + 1])
ans[a[i + 1]] += ans[a[i]];
}
cout << ans[a[n - 1]].x << endl;
return 0;
}
| #include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const int mod = 1000000007;
struct mint {
ll x;
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 {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
mint inv() const { return pow(mod - 2); }
mint &operator/=(const mint a) { return (*this) *= a.inv(); }
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
bool operator==(const mint a) { return x == a.x; }
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<int> a(n);
rep(i, n) {
cin >> a[i];
--a[i];
}
vector<mint> ans(200005, 0);
ans[a[0]] = 1;
rep(i, n - 1) {
if (a[i] != a[i + 1])
ans[a[i + 1]] += ans[a[i]];
}
cout << ans[a[n - 1]].x << endl;
return 0;
}
| [
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change",
"expression.operation.binary.change",
"expression.operation.binary.remove"
] | 906,942 | 906,943 | u415325136 | cpp |
p03096 | //#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define rep(i, n) FOR(i, 0, n)
#define ROF(i, a, b) for (ll i = a; i >= b; i--)
#define per(i, a) ROF(i, a, 0)
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
using ch = char;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ld PI = acos(-1);
const ll INF = 1e18;
struct edge {
ll to, cost;
};
struct edge2 {
ll from, to, cost;
};
template <typename T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
vP c(N);
rep(i, N) {
cin >> c[i].first;
c[i].second = i;
}
sort(c.begin(), c.end());
vl before(N, -1);
rep(i, N) {
if (c[i].first == c[i + 1].first) {
before[c[i + 1].second] = c[i].second;
}
}
ll dp[N];
rep(i, N) { dp[i] = 0; }
dp[0] = 1;
rep(i, N - 1) {
dp[i + 1] = dp[i];
if (before[i + 1] != -1 && before[i + 1] != i) {
dp[i + 1] += dp[before[i + 1]];
}
dp[i + 1] %= MOD;
}
rep(i, N) { cout << i << ' ' << dp[i] << endl; }
cout << dp[N - 1] << endl;
} | //#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define rep(i, n) FOR(i, 0, n)
#define ROF(i, a, b) for (ll i = a; i >= b; i--)
#define per(i, a) ROF(i, a, 0)
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
using ch = char;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ld PI = acos(-1);
const ll INF = 1e18;
struct edge {
ll to, cost;
};
struct edge2 {
ll from, to, cost;
};
template <typename T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
vP c(N);
rep(i, N) {
cin >> c[i].first;
c[i].second = i;
}
sort(c.begin(), c.end());
vl before(N, -1);
rep(i, N) {
if (c[i].first == c[i + 1].first) {
before[c[i + 1].second] = c[i].second;
}
}
ll dp[N];
rep(i, N) { dp[i] = 0; }
dp[0] = 1;
rep(i, N - 1) {
dp[i + 1] = dp[i];
if (before[i + 1] != -1 && before[i + 1] != i) {
dp[i + 1] += dp[before[i + 1]];
}
dp[i + 1] %= MOD;
}
rep(i, N) { cerr << i << ' ' << dp[i] << '\n'; }
cout << dp[N - 1] << endl;
}
| [
"identifier.change",
"expression.operation.binary.change"
] | 906,951 | 906,952 | u328811800 | cpp |
p03096 | //#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define rep(i, n) FOR(i, 0, n)
#define ROF(i, a, b) for (ll i = a; i >= b; i--)
#define per(i, a) ROF(i, a, 0)
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
using ch = char;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ld PI = acos(-1);
const ll INF = 1e18;
struct edge {
ll to, cost;
};
struct edge2 {
ll from, to, cost;
};
template <typename T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
vP c(N);
rep(i, N) {
cin >> c[i].first;
c[i].second = i;
}
sort(c.begin(), c.end());
vl before(N, -1);
rep(i, N) {
if (c[i].first == c[i + 1].first) {
before[c[i + 1].second] = c[i].second;
}
}
ll dp[N];
rep(i, N) { dp[i] = 0; }
dp[0] = 1;
rep(i, N - 1) {
dp[i + 1] = dp[i];
if (before[i + 1] != -1 && before[i + 1] != i) {
dp[i + 1] += dp[before[i + 1]];
}
dp[i + 1] %= MOD;
}
rep(i, N) { cout << i << ' ' << dp[i] << endl; }
cout << dp[N - 1] << endl;
} | //#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define rep(i, n) FOR(i, 0, n)
#define ROF(i, a, b) for (ll i = a; i >= b; i--)
#define per(i, a) ROF(i, a, 0)
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
using ch = char;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ld PI = acos(-1);
const ll INF = 1e18;
struct edge {
ll to, cost;
};
struct edge2 {
ll from, to, cost;
};
template <typename T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
vP c(N);
rep(i, N) {
cin >> c[i].first;
c[i].second = i;
}
sort(c.begin(), c.end());
vl before(N, -1);
rep(i, N) {
if (c[i].first == c[i + 1].first) {
before[c[i + 1].second] = c[i].second;
}
}
ll dp[N];
rep(i, N) { dp[i] = 0; }
dp[0] = 1;
rep(i, N - 1) {
dp[i + 1] = dp[i];
if (before[i + 1] != -1 && before[i + 1] != i) {
dp[i + 1] += dp[before[i + 1]];
}
dp[i + 1] %= MOD;
}
rep(i, N) { cerr << i << ' ' << dp[i] << endl; }
cout << dp[N - 1] << endl;
} | [
"identifier.change",
"expression.operation.binary.change"
] | 906,951 | 906,953 | u328811800 | cpp |
p03096 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll(i) = 0; (i) < (ll)(n); (i)++)
#define frep(i, m, n) for (ll(i) = (m); (i) <= (ll)(n); (i)++)
#define rrep(i, n) for (ll(i) = (n)-1; (i) > -1; (i)--)
#define frrep(i, m, n) for (ll(i) = (n); (i) > (ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()
const ll INF = 100100100100100100;
const ll MOD = 1000000007;
// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD
ll inv(ll a);
// (a+b+c)%MOD
ll madd(ll a, ll b, ll c);
// (a-b)%MOD
ll msub(ll a, ll b);
// (a*b*c)%MOD
ll mtime(ll a, ll b, ll c);
int main() {
ll n;
cin >> n;
vector<ll> c;
vector<vector<ll>> place(n + 1, vector<ll>());
rep(i, n) {
ll tmp;
cin >> tmp;
if (i > 0)
if (c[c.size() - 1] == tmp)
continue;
c.push_back(tmp);
}
rep(i, c.size()) { place[c[i]].push_back(i); }
vector<ll> dp(c.size() + 1, 0);
dp[0] = 1;
frep(i, 1, c.size()) {
dp[i] = madd(dp[i], dp[i - 1], 0);
ll color = c[i - 1];
auto iter = lower_bound(ALL(place[color]), i - 1) - place[color].begin();
if (iter > 0 && place[color][iter - 1] + 1 != i - 1) {
dp[i] = madd(dp[i], dp[place[color][iter - 1] + 1], 0);
}
}
cout << dp[c.size()] << endl;
return 0;
}
ll my_abs(ll a) {
if (a >= 0)
return a;
else
return -1 * a;
}
ll a_n(ll a, ll n) {
if (n == 0)
return 1;
ll ret = a, count = 1;
while (count * 2 < n) {
ret *= ret;
count *= 2;
}
if (count == n)
return ret;
else
return (ret * a_n(a, n - count));
}
ll my_gcd(ll a, ll b) {
if (b == 0)
return a;
return my_gcd(b, a % b);
}
ll inv(ll a) { return a_n(a, MOD - 2); }
ll madd(ll a, ll b, ll c) {
ll ret = (a + b) % MOD;
return (ret + c) % MOD;
}
ll msub(ll a, ll b) {
if (a < b)
return (a - b + MOD) % MOD;
else
return (a - b) % MOD;
}
ll mtime(ll a, ll b, ll c) {
ll ret = (a * b) % MOD;
return (ret * c) % MOD;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll(i) = 0; (i) < (ll)(n); (i)++)
#define frep(i, m, n) for (ll(i) = (m); (i) <= (ll)(n); (i)++)
#define rrep(i, n) for (ll(i) = (n)-1; (i) > -1; (i)--)
#define frrep(i, m, n) for (ll(i) = (n); (i) > (ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()
const ll INF = 100100100100100100;
const ll MOD = 1000000007;
// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD
ll inv(ll a);
// (a+b+c)%MOD
ll madd(ll a, ll b, ll c);
// (a-b)%MOD
ll msub(ll a, ll b);
// (a*b*c)%MOD
ll mtime(ll a, ll b, ll c);
int main() {
ll n;
cin >> n;
vector<ll> c;
vector<vector<ll>> place(200005, vector<ll>());
rep(i, n) {
ll tmp;
cin >> tmp;
if (i > 0)
if (c[c.size() - 1] == tmp)
continue;
c.push_back(tmp);
}
rep(i, c.size()) { place[c[i]].push_back(i); }
vector<ll> dp(c.size() + 1, 0);
dp[0] = 1;
frep(i, 1, c.size()) {
dp[i] = madd(dp[i], dp[i - 1], 0);
ll color = c[i - 1];
auto iter = lower_bound(ALL(place[color]), i - 1) - place[color].begin();
if (iter > 0 && place[color][iter - 1] + 1 != i - 1) {
dp[i] = madd(dp[i], dp[place[color][iter - 1] + 1], 0);
}
}
cout << dp[c.size()] << endl;
return 0;
}
ll my_abs(ll a) {
if (a >= 0)
return a;
else
return -1 * a;
}
ll a_n(ll a, ll n) {
if (n == 0)
return 1;
ll ret = a, count = 1;
while (count * 2 < n) {
ret *= ret;
count *= 2;
}
if (count == n)
return ret;
else
return (ret * a_n(a, n - count));
}
ll my_gcd(ll a, ll b) {
if (b == 0)
return a;
return my_gcd(b, a % b);
}
ll inv(ll a) { return a_n(a, MOD - 2); }
ll madd(ll a, ll b, ll c) {
ll ret = (a + b) % MOD;
return (ret + c) % MOD;
}
ll msub(ll a, ll b) {
if (a < b)
return (a - b + MOD) % MOD;
else
return (a - b) % MOD;
}
ll mtime(ll a, ll b, ll c) {
ll ret = (a * b) % MOD;
return (ret * c) % MOD;
}
| [
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change",
"expression.operation.binary.change",
"expression.operation.binary.remove"
] | 906,965 | 906,966 | u014442925 | cpp |
p03096 | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef pair<int, int> ii;
typedef long long ll;
typedef pair<ll, ll> P;
typedef unsigned long long int ull;
const ll MOD = 1e9 + 7;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
const int MAXN = 100000;
const int MAXE = 100000;
const int MAXV = 10000;
const ll INF = 2e9;
struct UnionFindTree {
vector<int> par, rank;
UnionFindTree(int n) : par(n), rank(n, 0) {
for (int i = 0; i < n; i++)
par[i] = i;
}
int root(int x) {
if (par[x] == x)
return x;
return par[x] = root(par[x]);
}
void unite(int x, int y) {
int rx = root(x), ry = root(y);
if (rx == ry)
return;
if (rank[rx] < rank[ry])
par[rx] = ry;
else
par[ry] = rx;
if (rank[rx] == rank[ry])
rank[rx]++;
}
bool same(int x, int y) { return root(x) == root(y); }
};
ll power(ll a, ll x) {
ll res = 1;
while (x > 0) {
if (x & 1)
res *= a;
a *= a;
x >>= 1;
}
return res;
}
int popcount(int x) {
int res = 0;
while (x > 0) {
if (x & 1)
res++;
x >>= 1;
}
return res;
}
ll f(ll x) {
ll res = 0;
while (x > 0) {
res += x % 10;
x /= 10;
}
return res;
}
int main() {
int n;
cin >> n;
vector<int> C(n);
for (int i = 0; i < n; i++)
cin >> C[i];
vector<ll> DP(n + 1, 0), L(200001, -1);
DP[0] = 1;
for (int i = 0; i < n; i++) {
DP[i + 1] = DP[i];
int c = C[i];
if (L[c] >= 0 && L[c] < i - 1) {
DP[i + 1] = (DP[i + 1] + DP[L[c] + 1]) % MOD;
L[c] = i;
}
}
cout << DP[n + 1] << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef pair<int, int> ii;
typedef long long ll;
typedef pair<ll, ll> P;
typedef unsigned long long int ull;
const ll MOD = 1e9 + 7;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
const int MAXN = 100000;
const int MAXE = 100000;
const int MAXV = 10000;
const ll INF = 2e9;
struct UnionFindTree {
vector<int> par, rank;
UnionFindTree(int n) : par(n), rank(n, 0) {
for (int i = 0; i < n; i++)
par[i] = i;
}
int root(int x) {
if (par[x] == x)
return x;
return par[x] = root(par[x]);
}
void unite(int x, int y) {
int rx = root(x), ry = root(y);
if (rx == ry)
return;
if (rank[rx] < rank[ry])
par[rx] = ry;
else
par[ry] = rx;
if (rank[rx] == rank[ry])
rank[rx]++;
}
bool same(int x, int y) { return root(x) == root(y); }
};
ll power(ll a, ll x) {
ll res = 1;
while (x > 0) {
if (x & 1)
res *= a;
a *= a;
x >>= 1;
}
return res;
}
int popcount(int x) {
int res = 0;
while (x > 0) {
if (x & 1)
res++;
x >>= 1;
}
return res;
}
ll f(ll x) {
ll res = 0;
while (x > 0) {
res += x % 10;
x /= 10;
}
return res;
}
int main() {
int n;
cin >> n;
vector<int> C(n);
for (int i = 0; i < n; i++)
cin >> C[i];
vector<ll> DP(n + 1, 0), L(200001, -1);
DP[0] = 1;
for (int i = 0; i < n; i++) {
DP[i + 1] = DP[i];
int c = C[i];
if (L[c] >= 0 && L[c] < i - 1) {
DP[i + 1] = (DP[i + 1] + DP[L[c] + 1]) % MOD;
}
L[c] = i;
}
cout << DP[n] << endl;
return 0;
} | [
"expression.operation.binary.remove"
] | 906,971 | 906,972 | u765815947 | cpp |
p03096 | #include <iostream>
#include <stdio.h>
//#include <bits/stdc++.h>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstring>
#include <float.h>
#include <iomanip>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define INF 1e18
#define rep(i, n) for (int i = 0; (i) < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); (i) <= (int)(b); i++)
#define VEC(type, c, n) \
std::vector<type> c(n); \
for (auto &i : c) \
std::cin >> i;
#define vec(type, n) vector<type>(n)
#define vvec(m, n) vector<vector<int>>(int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;
const int MOD = 1e9 + 7;
ll dp[200010];
int main() {
int n;
cin >> n;
vector<int> a(n);
rep(i, n) cin >> a[i];
vector<int> tab(n + 1, -1);
dp[0] = 1;
rep(i, n) {
if (tab[a[i]] == -1 || tab[a[i]] == i) {
dp[i + 1] = dp[i] % MOD;
} else {
dp[i + 1] = (dp[i] + dp[tab[a[i]]]) % MOD;
}
tab[a[i]] = i + 1;
}
cout << dp[n] << endl;
}
| #include <iostream>
#include <stdio.h>
//#include <bits/stdc++.h>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstring>
#include <float.h>
#include <iomanip>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define INF 1e18
#define rep(i, n) for (int i = 0; (i) < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); (i) <= (int)(b); i++)
#define VEC(type, c, n) \
std::vector<type> c(n); \
for (auto &i : c) \
std::cin >> i;
#define vec(type, n) vector<type>(n)
#define vvec(m, n) vector<vector<int>>(int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;
const int MOD = 1e9 + 7;
ll dp[200010];
int main() {
int n;
cin >> n;
vector<int> a(n);
rep(i, n) cin >> a[i];
vector<int> tab(200010, -1);
dp[0] = 1;
rep(i, n) {
if (tab[a[i]] == -1 || tab[a[i]] == i) {
dp[i + 1] = dp[i] % MOD;
} else {
dp[i + 1] = (dp[i] + dp[tab[a[i]]]) % MOD;
}
tab[a[i]] = i + 1;
}
cout << dp[n] << endl;
}
| [
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change",
"expression.operation.binary.change",
"expression.operation.binary.remove"
] | 906,973 | 906,974 | u516525290 | cpp |
p03096 | #include <bits/stdc++.h>
using namespace std;
// long long
using ll = long long;
// pair<int, int>
using PII = pair<int, int>;
//最大値、mod
const int MOD = 1000000007;
const int mod = 1000000007;
const int INF = 1000000000;
const long long LINF = 1e18;
const int MAX = 510000;
//出力系
#define print(x) cout << x << endl
#define prints(x) cout << fixed << setprecision(20) << x << endl
#define printc(x) cout << setw(2) << setfill('0') << x << endl;
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
// begin() end()
#define all(x) (x).begin(), (x).end()
// for
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rrep(i, a, b) for (int i = (a); i > (b); i--)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
//最大公約数
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
// 最小公倍数
unsigned lcm(unsigned a, unsigned b) { return a / gcd(a, b) * b; }
// a = max(a, b), a = min(a, b)
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
// 階乗(MODをとる)
ll pow_mod(ll num, ll pow, ll mod) {
ll prod = 1;
num %= mod;
while (pow > 0) {
if (pow & 1)
prod = prod * num % mod;
num = num * num % mod;
pow >>= 1;
}
return prod;
}
// 二項係数(MODとる、1 ≦ k ≦ n ≦ 10^7 程度)
// COMinit()
// COM(x, y)
// とコンビで使う
// テーブルを作る前処理
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// UnionFind
struct UnionFind {
vector<int> par;
vector<int> rank;
vector<ll> Size;
UnionFind(int n = 1) { init(n); }
void init(int n = 1) {
par.resize(n + 1);
rank.resize(n + 1);
Size.resize(n + 1);
for (int i = 0; i <= n; ++i)
par[i] = i, rank[i] = 0, Size[i] = 1;
}
int root(int x) {
if (par[x] == x) {
return x;
} else {
int r = root(par[x]);
return par[x] = r;
}
}
bool issame(int x, int y) { return root(x) == root(y); }
bool merge(int x, int y) {
x = root(x);
y = root(y);
if (x == y)
return false;
if (rank[x] < rank[y])
swap(x, y);
if (rank[x] == rank[y])
++rank[x];
par[y] = x;
Size[x] += Size[y];
return true;
}
ll size(int x) { return Size[root(x)]; }
};
// modint構造体
struct Mint {
int val;
Mint inv() const {
int tmp, a = val, b = mod, x = 1, y = 0;
while (b)
tmp = a / b, a -= tmp * b, swap(a, b), x -= tmp * y, swap(x, y);
return Mint(x);
}
public:
Mint() : val(0) {}
Mint(ll x) {
if ((val = x % mod) < 0)
val += mod;
}
Mint pow(ll t) {
Mint res = 1, b = *this;
while (t) {
if (t & 1)
res *= b;
b *= b;
t >>= 1;
}
return res;
}
Mint &operator+=(const Mint &x) {
if ((val += x.val) >= mod)
val -= mod;
return *this;
}
Mint &operator-=(const Mint &x) {
if ((val += mod - x.val) >= mod)
val -= mod;
return *this;
}
Mint &operator*=(const Mint &x) {
val = (ll)val * x.val % mod;
return *this;
}
Mint &operator/=(const Mint &x) { return *this *= x.inv(); }
bool operator==(const Mint &x) const { return val == x.val; }
bool operator!=(const Mint &x) const { return val != x.val; }
bool operator<(const Mint &x) const { return val < x.val; }
bool operator<=(const Mint &x) const { return val <= x.val; }
bool operator>(const Mint &x) const { return val > x.val; }
bool operator>=(const Mint &x) const { return val >= x.val; }
Mint operator+(const Mint &x) const { return Mint(*this) += x; }
Mint operator-(const Mint &x) const { return Mint(*this) -= x; }
Mint operator*(const Mint &x) const { return Mint(*this) *= x; }
Mint operator/(const Mint &x) const { return Mint(*this) /= x; }
};
struct factorial {
vector<Mint> Fact, Finv;
public:
// factorial fact(10000010);
// fact.nCr(a, b)
//「fact」の部分は自由に名前変更可能
factorial(int maxx) {
Fact.resize(maxx + 1), Finv.resize(maxx + 1);
Fact[0] = Mint(1);
rep(i, 0, maxx) Fact[i + 1] = Fact[i] * (i + 1);
Finv[maxx] = Mint(1) / Fact[maxx];
rrep(i, maxx, 0) Finv[i - 1] = Finv[i] * i;
}
Mint fact(int n, bool inv = 0) {
if (inv)
return Finv[n];
else
return Fact[n];
}
Mint nPr(int n, int r) {
if (n < 0 || n < r || r < 0)
return Mint(0);
else
return Fact[n] * Finv[n - r];
}
Mint nCr(int n, int r) {
if (n < 0 || n < r || r < 0)
return Mint(0);
else
return Fact[n] * Finv[r] * Finv[n - r];
}
};
// 1 * 2 * 3 .... * n (mod)
ll modfact(ll n) {
if (n <= 1)
return 1;
return (n * modfact(n - 1)) % MOD;
}
// kが角度だった場合:cos(k * (PI / 180));
const double PI = acos(-1);
// 多次元vector生成 例: auto dp = make_vec<long long>(N+1, 5, 5, 5);
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
//素因数分解
vector<pair<ll, int>> factorize(ll n) {
vector<pair<ll, int>> res;
for (ll i = 2; i * i <= n; ++i) {
if (n % i)
continue;
res.emplace_back(i, 0);
while (n % i == 0) {
n /= i;
res.back().second++;
}
}
if (n != 1)
res.emplace_back(n, 1);
return res;
}
// 素数判定(マイナスは素数でないと判定するタイプ)
bool primejudge(ll a) {
if (a <= 1)
return false;
for (ll i = 2; i * i <= a; i++) {
if (a % i == 0)
return false;
}
return true;
}
int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};
int main() {
int n;
cin >> n;
int c[n];
REP(i, n) { cin >> c[i]; }
vector<int> left(n, -1);
vector<int> dp(n + 1);
dp[0] = 1;
for (int i = 0; i < n; i++) {
dp[i + 1] = (dp[i + 1] + dp[i]) % MOD;
int C = c[i];
if (left[C] >= 0 && left[C] < i - 1)
dp[i + 1] = (dp[i + 1] + dp[left[C] + 1]) % MOD;
left[C] = i;
}
cout << dp[n] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
// long long
using ll = long long;
// pair<int, int>
using PII = pair<int, int>;
//最大値、mod
const int MOD = 1000000007;
const int mod = 1000000007;
const int INF = 1000000000;
const long long LINF = 1e18;
const int MAX = 510000;
//出力系
#define print(x) cout << x << endl
#define prints(x) cout << fixed << setprecision(20) << x << endl
#define printc(x) cout << setw(2) << setfill('0') << x << endl;
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
// begin() end()
#define all(x) (x).begin(), (x).end()
// for
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rrep(i, a, b) for (int i = (a); i > (b); i--)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
//最大公約数
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
// 最小公倍数
unsigned lcm(unsigned a, unsigned b) { return a / gcd(a, b) * b; }
// a = max(a, b), a = min(a, b)
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
// 階乗(MODをとる)
ll pow_mod(ll num, ll pow, ll mod) {
ll prod = 1;
num %= mod;
while (pow > 0) {
if (pow & 1)
prod = prod * num % mod;
num = num * num % mod;
pow >>= 1;
}
return prod;
}
// 二項係数(MODとる、1 ≦ k ≦ n ≦ 10^7 程度)
// COMinit()
// COM(x, y)
// とコンビで使う
// テーブルを作る前処理
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// UnionFind
struct UnionFind {
vector<int> par;
vector<int> rank;
vector<ll> Size;
UnionFind(int n = 1) { init(n); }
void init(int n = 1) {
par.resize(n + 1);
rank.resize(n + 1);
Size.resize(n + 1);
for (int i = 0; i <= n; ++i)
par[i] = i, rank[i] = 0, Size[i] = 1;
}
int root(int x) {
if (par[x] == x) {
return x;
} else {
int r = root(par[x]);
return par[x] = r;
}
}
bool issame(int x, int y) { return root(x) == root(y); }
bool merge(int x, int y) {
x = root(x);
y = root(y);
if (x == y)
return false;
if (rank[x] < rank[y])
swap(x, y);
if (rank[x] == rank[y])
++rank[x];
par[y] = x;
Size[x] += Size[y];
return true;
}
ll size(int x) { return Size[root(x)]; }
};
// modint構造体
struct Mint {
int val;
Mint inv() const {
int tmp, a = val, b = mod, x = 1, y = 0;
while (b)
tmp = a / b, a -= tmp * b, swap(a, b), x -= tmp * y, swap(x, y);
return Mint(x);
}
public:
Mint() : val(0) {}
Mint(ll x) {
if ((val = x % mod) < 0)
val += mod;
}
Mint pow(ll t) {
Mint res = 1, b = *this;
while (t) {
if (t & 1)
res *= b;
b *= b;
t >>= 1;
}
return res;
}
Mint &operator+=(const Mint &x) {
if ((val += x.val) >= mod)
val -= mod;
return *this;
}
Mint &operator-=(const Mint &x) {
if ((val += mod - x.val) >= mod)
val -= mod;
return *this;
}
Mint &operator*=(const Mint &x) {
val = (ll)val * x.val % mod;
return *this;
}
Mint &operator/=(const Mint &x) { return *this *= x.inv(); }
bool operator==(const Mint &x) const { return val == x.val; }
bool operator!=(const Mint &x) const { return val != x.val; }
bool operator<(const Mint &x) const { return val < x.val; }
bool operator<=(const Mint &x) const { return val <= x.val; }
bool operator>(const Mint &x) const { return val > x.val; }
bool operator>=(const Mint &x) const { return val >= x.val; }
Mint operator+(const Mint &x) const { return Mint(*this) += x; }
Mint operator-(const Mint &x) const { return Mint(*this) -= x; }
Mint operator*(const Mint &x) const { return Mint(*this) *= x; }
Mint operator/(const Mint &x) const { return Mint(*this) /= x; }
};
struct factorial {
vector<Mint> Fact, Finv;
public:
// factorial fact(10000010);
// fact.nCr(a, b)
//「fact」の部分は自由に名前変更可能
factorial(int maxx) {
Fact.resize(maxx + 1), Finv.resize(maxx + 1);
Fact[0] = Mint(1);
rep(i, 0, maxx) Fact[i + 1] = Fact[i] * (i + 1);
Finv[maxx] = Mint(1) / Fact[maxx];
rrep(i, maxx, 0) Finv[i - 1] = Finv[i] * i;
}
Mint fact(int n, bool inv = 0) {
if (inv)
return Finv[n];
else
return Fact[n];
}
Mint nPr(int n, int r) {
if (n < 0 || n < r || r < 0)
return Mint(0);
else
return Fact[n] * Finv[n - r];
}
Mint nCr(int n, int r) {
if (n < 0 || n < r || r < 0)
return Mint(0);
else
return Fact[n] * Finv[r] * Finv[n - r];
}
};
// 1 * 2 * 3 .... * n (mod)
ll modfact(ll n) {
if (n <= 1)
return 1;
return (n * modfact(n - 1)) % MOD;
}
// kが角度だった場合:cos(k * (PI / 180));
const double PI = acos(-1);
// 多次元vector生成 例: auto dp = make_vec<long long>(N+1, 5, 5, 5);
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
//素因数分解
vector<pair<ll, int>> factorize(ll n) {
vector<pair<ll, int>> res;
for (ll i = 2; i * i <= n; ++i) {
if (n % i)
continue;
res.emplace_back(i, 0);
while (n % i == 0) {
n /= i;
res.back().second++;
}
}
if (n != 1)
res.emplace_back(n, 1);
return res;
}
// 素数判定(マイナスは素数でないと判定するタイプ)
bool primejudge(ll a) {
if (a <= 1)
return false;
for (ll i = 2; i * i <= a; i++) {
if (a % i == 0)
return false;
}
return true;
}
int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};
int main() {
int n;
cin >> n;
int c[n];
REP(i, n) { cin >> c[i]; }
vector<int> left(200010, -1);
vector<int> dp(n + 1);
dp[0] = 1;
for (int i = 0; i < n; i++) {
dp[i + 1] = (dp[i + 1] + dp[i]) % MOD;
int C = c[i];
if (left[C] >= 0 && left[C] < i - 1)
dp[i + 1] = (dp[i + 1] + dp[left[C] + 1]) % MOD;
left[C] = i;
}
cout << dp[n] << endl;
return 0;
}
| [
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change"
] | 906,983 | 906,984 | u832995587 | cpp |
p03096 | #include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, n) for (int i = 1; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000000;
constexpr int mod = 1000000007;
struct ModInt {
ll x;
ModInt(ll a) : x((a % mod + mod) % mod) {}
ModInt operator-() const { return ModInt(-x); }
ModInt &operator+=(const ModInt &a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
ModInt &operator-=(const ModInt &a) {
if ((x -= a.x) < 0)
x += mod;
return *this;
}
ModInt &operator*=(const ModInt &a) {
(x *= a.x) %= mod;
return *this;
}
ModInt operator+(const ModInt &a) const {
ModInt res(*this);
return res += a;
}
ModInt operator-(const ModInt &a) const {
ModInt res(*this);
return res -= a;
}
ModInt operator*(const ModInt &a) const {
ModInt res(*this);
return res *= a;
}
ModInt pow(ll t) const {
if (!t)
return 1;
ModInt a = pow(t / 2);
a *= a;
if (t & 1)
a *= *this;
return a;
}
ModInt inv() const { return pow(mod - 2); }
ModInt &operator/=(const ModInt &a) { return (*this) *= a.inv(); }
ModInt operator/(const ModInt &a) const {
ModInt res(*this);
return res /= a;
}
friend ostream &operator<<(ostream &os, const ModInt &a) {
os << a.x;
return os;
}
};
constexpr int c_max = 10;
int main() {
int N;
cin >> N;
vector<int> C;
rep(i, N) {
int c;
cin >> c;
if (i) {
if (c != C.back()) {
C.push_back(c);
}
} else {
C.push_back(c);
}
}
vector<ModInt> dp;
dp.push_back(ModInt{1});
vector<int> MX(c_max, -1);
MX[C[0]] = 0;
REP(i, SZ(C)) {
ModInt res = dp.back();
if (MX[C[i]] != -1)
res += dp[MX[C[i]]];
dp.push_back(res);
MX[C[i]] = i;
}
cout << dp.back() << "\n";
return 0;
}
| #include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, n) for (int i = 1; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000000;
constexpr int mod = 1000000007;
struct ModInt {
ll x;
ModInt(ll a) : x((a % mod + mod) % mod) {}
ModInt operator-() const { return ModInt(-x); }
ModInt &operator+=(const ModInt &a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
ModInt &operator-=(const ModInt &a) {
if ((x -= a.x) < 0)
x += mod;
return *this;
}
ModInt &operator*=(const ModInt &a) {
(x *= a.x) %= mod;
return *this;
}
ModInt operator+(const ModInt &a) const {
ModInt res(*this);
return res += a;
}
ModInt operator-(const ModInt &a) const {
ModInt res(*this);
return res -= a;
}
ModInt operator*(const ModInt &a) const {
ModInt res(*this);
return res *= a;
}
ModInt pow(ll t) const {
if (!t)
return 1;
ModInt a = pow(t / 2);
a *= a;
if (t & 1)
a *= *this;
return a;
}
ModInt inv() const { return pow(mod - 2); }
ModInt &operator/=(const ModInt &a) { return (*this) *= a.inv(); }
ModInt operator/(const ModInt &a) const {
ModInt res(*this);
return res /= a;
}
friend ostream &operator<<(ostream &os, const ModInt &a) {
os << a.x;
return os;
}
};
constexpr int c_max = 200010;
int main() {
int N;
cin >> N;
vector<int> C;
rep(i, N) {
int c;
cin >> c;
if (i) {
if (c != C.back()) {
C.push_back(c);
}
} else {
C.push_back(c);
}
}
vector<ModInt> dp;
dp.push_back(ModInt{1});
vector<int> MX(c_max, -1);
MX[C[0]] = 0;
REP(i, SZ(C)) {
ModInt res = dp.back();
if (MX[C[i]] != -1)
res += dp[MX[C[i]]];
dp.push_back(res);
MX[C[i]] = i;
}
cout << dp.back() << "\n";
return 0;
}
| [
"literal.number.change",
"variable_declaration.value.change"
] | 906,991 | 906,990 | u826189900 | cpp |
p03096 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
int main() {
int n;
cin >> n;
vector<int> c(n);
for (int i = 0; i < n; i++)
cin >> c[i];
c.erase(unique(c.begin(), c.end()), c.end());
int C = *max_element(c.begin(), c.end());
n = c.size();
vector<ll> dp(n + 1, 0);
dp[0] = 1;
vector<int> sm(C + 1, 0);
for (int i = 0; i < n; i++) {
dp[i + 1] = (dp[i] + sm[c[i]]) % MOD;
sm[c[i]] += dp[i + 1];
sm[c[i]] %= MOD;
}
cout << dp[n] << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
int main() {
int n;
cin >> n;
vector<int> c(n);
for (int i = 0; i < n; i++)
cin >> c[i];
c.erase(unique(c.begin(), c.end()), c.end());
int C = *max_element(c.begin(), c.end());
n = c.size();
vector<ll> dp(n + 1, 0);
dp[0] = 1;
vector<int> sm(C + 1, 0);
for (int i = 0; i < n; i++) {
dp[i + 1] = (dp[i] + sm[c[i]]) % MOD;
sm[c[i]] += dp[i];
sm[c[i]] %= MOD;
}
cout << dp[n] << endl;
} | [
"expression.operation.binary.remove"
] | 906,996 | 906,997 | u813174766 | cpp |
p03096 | #include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <vector>
using namespace std;
#define long long ll
#define rep(s, i, n) for (int i = s; i < n; i++)
#define c(n) cout << n << endl;
#define ic(n) \
int n; \
cin >> n;
#define sc(s) \
string s; \
cin >> s;
#define mod 1000000007
#define inf 1000000000000000007
#define f first
#define s second
#define mini(c, a, b) *min_element(c + a, c + b)
#define maxi(c, a, b) *max_element(c + a, c + b)
#define pi 3.141592653589793238462643383279
#define e_ 2.718281828459045235360287471352
#define P pair<int, int>
#define upp(a, n, x) upper_bound(a, a + n, x) - a;
#define low(a, n, x) lower_bound(a, a + n, x) - a;
#define UF UnionFind
// printf("%.12Lf\n",);
int keta(int x) {
rep(0, i, 30) {
if (x < 10) {
return i + 1;
}
x = x / 10;
}
}
int gcd(int x, int y) {
if (x == 0 || y == 0)
return x + y;
int aa = x, bb = y;
rep(0, i, 1000) {
aa = aa % bb;
if (aa == 0) {
return bb;
}
bb = bb % aa;
if (bb == 0) {
return aa;
}
}
}
int lcm(int x, int y) {
int aa = x, bb = y;
rep(0, i, 1000) {
aa = aa % bb;
if (aa == 0) {
return x / bb * y;
}
bb = bb % aa;
if (bb == 0) {
return x / aa * y;
}
}
}
bool p(int x) {
if (x == 1)
return false;
rep(2, i, sqrt(x) + 1) {
if (x % i == 0 && x != i) {
return false;
}
}
return true;
}
int max(int a, int b) {
if (a >= b)
return a;
else
return b;
}
string maxst(string s, string t) {
int n = s.size();
int m = t.size();
if (n > m)
return s;
else if (n < m)
return t;
else {
rep(0, i, n) {
if (s[i] > t[i])
return s;
if (s[i] < t[i])
return t;
}
return s;
}
}
int min(int a, int b) {
if (a >= b)
return b;
else
return a;
}
int n2[41];
int nis[41];
int nia[41];
int mody[41];
int nn;
int com(int n, int y) {
int ni = 1;
for (int i = 0; i < 41; i++) {
n2[i] = ni;
ni *= 2;
}
int bunsi = 1, bunbo = 1;
rep(0, i, y) bunsi = (bunsi * (n - i)) % mod;
rep(0, i, y) bunbo = (bunbo * (i + 1)) % mod;
mody[0] = bunbo;
rep(1, i, 41) {
bunbo = (bunbo * bunbo) % mod;
mody[i] = bunbo;
}
rep(0, i, 41) nis[i] = 0;
nn = mod - 2;
for (int i = 40; i >= 0; i -= 1) {
if (nn > n2[i]) {
nis[i]++;
nn -= n2[i];
}
}
nis[0]++;
rep(0, i, 41) {
if (nis[i] == 1) {
bunsi = (bunsi * mody[i]) % mod;
}
}
return bunsi;
}
int gyakugen(int n, int y) {
int ni = 1;
for (int i = 0; i < 41; i++) {
n2[i] = ni;
ni *= 2;
}
mody[0] = y;
rep(1, i, 41) {
y = (y * y) % mod;
mody[i] = y;
}
rep(0, i, 41) nis[i] = 0;
nn = mod - 2;
for (int i = 40; i >= 0; i -= 1) {
if (nn > n2[i]) {
nis[i]++;
nn -= n2[i];
}
}
nis[0]++;
rep(0, i, 41) {
if (nis[i] == 1) {
n = (n * mody[i]) % mod;
}
}
return n;
}
int yakuwa(int n) {
int sum = 0;
rep(1, i, sqrt(n + 1)) {
if (n % i == 0)
sum += i + n / i;
if (i * i == n)
sum -= i;
}
return sum;
}
int poow(int y, int n) {
if (n == 0)
return 1;
n -= 1;
int ni = 1;
for (int i = 0; i < 41; i++) {
n2[i] = ni;
ni *= 2;
}
int yy = y;
mody[0] = yy;
rep(1, i, 41) {
yy = (yy * yy) % mod;
mody[i] = yy;
}
rep(0, i, 41) nis[i] = 0;
nn = n;
for (int i = 40; i >= 0; i -= 1) {
if (nn >= n2[i]) {
nis[i]++;
nn -= n2[i];
}
}
rep(0, i, 41) {
if (nis[i] == 1) {
y = (y * mody[i]) % mod;
}
}
return y;
}
int minpow(int x, int y) {
int sum = 1;
rep(0, i, y) sum *= x;
return sum;
}
int ketawa(int x, int sinsuu) {
int sum = 0;
rep(0, i, 100) sum += (x % poow(sinsuu, i + 1)) / (poow(sinsuu, i));
return sum;
}
int sankaku(int a) { return a * (a + 1) / 2; }
int sames(int a[1111111], int n) {
int ans = 0;
rep(0, i, n) {
if (a[i] == a[i + 1]) {
int j = i;
while (a[j + 1] == a[i] && j <= n - 2)
j++;
ans += sankaku(j - i);
i = j;
}
}
return ans;
}
/*using Graph=vector<vector<int>>;
int oya[114514];
int depth[114514];
void dfs(const Graph &G, int v, int p, int d) {
depth[v] = d;
oya[v]=p;
for (auto nv : G[v]) {
if (nv == p) continue; // nv が親 p だったらダメ
dfs(G, nv, v, d+1); // d を 1 増やして子ノードへ
}
}*/
/*int H=10,W=10;
char field[10][10];
char memo[10][10];
void dfs(int h, int w) {
memo[h][w] = 'x';
// 八方向を探索
for (int dh = -1; dh <= 1; ++dh) {
for (int dw = -1; dw <= 1; ++dw) {
if(abs(0-dh)+abs(0-dw)==2)continue;
int nh = h + dh, nw = w + dw;
// 場外アウトしたり、0 だったりはスルー
if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
if (memo[nh][nw] == 'x') continue;
// 再帰的に探索
dfs(nh, nw);
}
}
}*/
int XOR(int a, int b) {
if (a == 0 || b == 0) {
return a + b;
}
int ni = 1;
rep(0, i, 41) {
n2[i] = ni;
ni *= 2;
}
rep(0, i, 41) nis[i] = 0;
for (int i = 40; i >= 0; i -= 1) {
if (a >= n2[i]) {
nis[i]++;
a -= n2[i];
}
if (b >= n2[i]) {
nis[i]++;
b -= n2[i];
}
}
int sum = 0;
rep(0, i, 41) sum += (nis[i] % 2 * n2[i]);
return sum;
}
// int ma[1024577][21];
// for(int bit=0;bit<(1<<n);bit++)rep(0,i,n)if(bit&(1<<i))ma[bit][i]=1;
struct UnionFind {
vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2
vector<int> siz;
UnionFind(int N) : par(N), siz(N) { //最初は全てが根であるとして初期化
for (int i = 0; i < N; i++) {
par[i] = i;
siz[i] = 1;
}
}
int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根}
if (par[x] == x)
return x;
return par[x] = root(par[x]);
}
void unite(int x, int y) { // xとyの木を併合
int rx = root(x); // xの根をrx
int ry = root(y); // yの根をry
if (rx == ry)
return; // xとyの根が同じ(=同じ木にある)時はそのまま
if (siz[rx] > siz[ry]) {
siz[rx] += siz[ry];
par[y] = x;
} else {
siz[ry] += siz[rx];
par[x] = y;
}
}
bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
int rx = root(x);
int ry = root(y);
return rx == ry;
}
int size(int x) { return siz[root(x)]; }
};
int dp[214514];
int a[214514];
vector<int> b;
vector<int> cnt[214514];
int fr[214514];
signed main() {
ic(n) rep(0, i, n) {
cin >> a[i];
if (i > 1 && a[i] == a[i - 1]) {
} else
b.push_back(a[i]);
}
int m = b.size();
rep(0, i, m) {
if (cnt[b[i]].empty()) {
fr[i] = -1;
} else {
fr[i] = cnt[b[i]][cnt[b[i]].size() - 1];
}
cnt[b[i]].push_back(i);
}
dp[0] = 1;
rep(1, i, m) {
if (fr[i] >= 0) {
dp[i] = (dp[i - 1] + dp[fr[i]]) % mod;
;
} else {
dp[i] = dp[i - 1];
}
dp[i] %= mod;
}
c(dp[m - 1] % mod)
}
| #include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <vector>
using namespace std;
#define long long ll
#define rep(s, i, n) for (int i = s; i < n; i++)
#define c(n) cout << n << endl;
#define ic(n) \
int n; \
cin >> n;
#define sc(s) \
string s; \
cin >> s;
#define mod 1000000007
#define inf 1000000000000000007
#define f first
#define s second
#define mini(c, a, b) *min_element(c + a, c + b)
#define maxi(c, a, b) *max_element(c + a, c + b)
#define pi 3.141592653589793238462643383279
#define e_ 2.718281828459045235360287471352
#define P pair<int, int>
#define upp(a, n, x) upper_bound(a, a + n, x) - a;
#define low(a, n, x) lower_bound(a, a + n, x) - a;
#define UF UnionFind
// printf("%.12Lf\n",);
int keta(int x) {
rep(0, i, 30) {
if (x < 10) {
return i + 1;
}
x = x / 10;
}
}
int gcd(int x, int y) {
if (x == 0 || y == 0)
return x + y;
int aa = x, bb = y;
rep(0, i, 1000) {
aa = aa % bb;
if (aa == 0) {
return bb;
}
bb = bb % aa;
if (bb == 0) {
return aa;
}
}
}
int lcm(int x, int y) {
int aa = x, bb = y;
rep(0, i, 1000) {
aa = aa % bb;
if (aa == 0) {
return x / bb * y;
}
bb = bb % aa;
if (bb == 0) {
return x / aa * y;
}
}
}
bool p(int x) {
if (x == 1)
return false;
rep(2, i, sqrt(x) + 1) {
if (x % i == 0 && x != i) {
return false;
}
}
return true;
}
int max(int a, int b) {
if (a >= b)
return a;
else
return b;
}
string maxst(string s, string t) {
int n = s.size();
int m = t.size();
if (n > m)
return s;
else if (n < m)
return t;
else {
rep(0, i, n) {
if (s[i] > t[i])
return s;
if (s[i] < t[i])
return t;
}
return s;
}
}
int min(int a, int b) {
if (a >= b)
return b;
else
return a;
}
int n2[41];
int nis[41];
int nia[41];
int mody[41];
int nn;
int com(int n, int y) {
int ni = 1;
for (int i = 0; i < 41; i++) {
n2[i] = ni;
ni *= 2;
}
int bunsi = 1, bunbo = 1;
rep(0, i, y) bunsi = (bunsi * (n - i)) % mod;
rep(0, i, y) bunbo = (bunbo * (i + 1)) % mod;
mody[0] = bunbo;
rep(1, i, 41) {
bunbo = (bunbo * bunbo) % mod;
mody[i] = bunbo;
}
rep(0, i, 41) nis[i] = 0;
nn = mod - 2;
for (int i = 40; i >= 0; i -= 1) {
if (nn > n2[i]) {
nis[i]++;
nn -= n2[i];
}
}
nis[0]++;
rep(0, i, 41) {
if (nis[i] == 1) {
bunsi = (bunsi * mody[i]) % mod;
}
}
return bunsi;
}
int gyakugen(int n, int y) {
int ni = 1;
for (int i = 0; i < 41; i++) {
n2[i] = ni;
ni *= 2;
}
mody[0] = y;
rep(1, i, 41) {
y = (y * y) % mod;
mody[i] = y;
}
rep(0, i, 41) nis[i] = 0;
nn = mod - 2;
for (int i = 40; i >= 0; i -= 1) {
if (nn > n2[i]) {
nis[i]++;
nn -= n2[i];
}
}
nis[0]++;
rep(0, i, 41) {
if (nis[i] == 1) {
n = (n * mody[i]) % mod;
}
}
return n;
}
int yakuwa(int n) {
int sum = 0;
rep(1, i, sqrt(n + 1)) {
if (n % i == 0)
sum += i + n / i;
if (i * i == n)
sum -= i;
}
return sum;
}
int poow(int y, int n) {
if (n == 0)
return 1;
n -= 1;
int ni = 1;
for (int i = 0; i < 41; i++) {
n2[i] = ni;
ni *= 2;
}
int yy = y;
mody[0] = yy;
rep(1, i, 41) {
yy = (yy * yy) % mod;
mody[i] = yy;
}
rep(0, i, 41) nis[i] = 0;
nn = n;
for (int i = 40; i >= 0; i -= 1) {
if (nn >= n2[i]) {
nis[i]++;
nn -= n2[i];
}
}
rep(0, i, 41) {
if (nis[i] == 1) {
y = (y * mody[i]) % mod;
}
}
return y;
}
int minpow(int x, int y) {
int sum = 1;
rep(0, i, y) sum *= x;
return sum;
}
int ketawa(int x, int sinsuu) {
int sum = 0;
rep(0, i, 100) sum += (x % poow(sinsuu, i + 1)) / (poow(sinsuu, i));
return sum;
}
int sankaku(int a) { return a * (a + 1) / 2; }
int sames(int a[1111111], int n) {
int ans = 0;
rep(0, i, n) {
if (a[i] == a[i + 1]) {
int j = i;
while (a[j + 1] == a[i] && j <= n - 2)
j++;
ans += sankaku(j - i);
i = j;
}
}
return ans;
}
/*using Graph=vector<vector<int>>;
int oya[114514];
int depth[114514];
void dfs(const Graph &G, int v, int p, int d) {
depth[v] = d;
oya[v]=p;
for (auto nv : G[v]) {
if (nv == p) continue; // nv が親 p だったらダメ
dfs(G, nv, v, d+1); // d を 1 増やして子ノードへ
}
}*/
/*int H=10,W=10;
char field[10][10];
char memo[10][10];
void dfs(int h, int w) {
memo[h][w] = 'x';
// 八方向を探索
for (int dh = -1; dh <= 1; ++dh) {
for (int dw = -1; dw <= 1; ++dw) {
if(abs(0-dh)+abs(0-dw)==2)continue;
int nh = h + dh, nw = w + dw;
// 場外アウトしたり、0 だったりはスルー
if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
if (memo[nh][nw] == 'x') continue;
// 再帰的に探索
dfs(nh, nw);
}
}
}*/
int XOR(int a, int b) {
if (a == 0 || b == 0) {
return a + b;
}
int ni = 1;
rep(0, i, 41) {
n2[i] = ni;
ni *= 2;
}
rep(0, i, 41) nis[i] = 0;
for (int i = 40; i >= 0; i -= 1) {
if (a >= n2[i]) {
nis[i]++;
a -= n2[i];
}
if (b >= n2[i]) {
nis[i]++;
b -= n2[i];
}
}
int sum = 0;
rep(0, i, 41) sum += (nis[i] % 2 * n2[i]);
return sum;
}
// int ma[1024577][21];
// for(int bit=0;bit<(1<<n);bit++)rep(0,i,n)if(bit&(1<<i))ma[bit][i]=1;
struct UnionFind {
vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2
vector<int> siz;
UnionFind(int N) : par(N), siz(N) { //最初は全てが根であるとして初期化
for (int i = 0; i < N; i++) {
par[i] = i;
siz[i] = 1;
}
}
int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根}
if (par[x] == x)
return x;
return par[x] = root(par[x]);
}
void unite(int x, int y) { // xとyの木を併合
int rx = root(x); // xの根をrx
int ry = root(y); // yの根をry
if (rx == ry)
return; // xとyの根が同じ(=同じ木にある)時はそのまま
if (siz[rx] > siz[ry]) {
siz[rx] += siz[ry];
par[y] = x;
} else {
siz[ry] += siz[rx];
par[x] = y;
}
}
bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
int rx = root(x);
int ry = root(y);
return rx == ry;
}
int size(int x) { return siz[root(x)]; }
};
int dp[214514];
int a[214514];
vector<int> b;
vector<int> cnt[214514];
int fr[214514];
signed main() {
ic(n) rep(0, i, n) {
cin >> a[i];
if (i > 0 && a[i] == a[i - 1]) {
} else
b.push_back(a[i]);
}
int m = b.size();
rep(0, i, m) {
if (cnt[b[i]].empty()) {
fr[i] = -1;
} else {
fr[i] = cnt[b[i]][cnt[b[i]].size() - 1];
}
cnt[b[i]].push_back(i);
}
dp[0] = 1;
rep(1, i, m) {
if (fr[i] >= 0) {
dp[i] = (dp[i - 1] + dp[fr[i]]) % mod;
;
} else {
dp[i] = dp[i - 1];
}
dp[i] %= mod;
}
c(dp[m - 1] % mod)
}
| [
"literal.number.change",
"control_flow.branch.if.condition.change"
] | 907,015 | 907,016 | u942393279 | cpp |
p03096 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD 1000000007
int N;
vector<int> C;
vector<int> memo;
vector<int> nearest;
vector<int> ind;
int f(int i) {
if (i >= nearest.size())
return 1;
if (memo[i] != -1)
return memo[i];
if (nearest[i] == -1) {
return memo[i] = f(i + 1) % MOD;
} else {
return memo[i] = (f(nearest[i]) + f(i + 1)) % MOD;
}
}
int main() {
cin >> N;
C.resize(N);
for (auto &e : C)
cin >> e;
C.erase(unique(C.begin(), C.end()), C.end());
ind.assign(N + 1, -1);
nearest.assign(C.size(), -1);
for (int i = C.size() - 1; i >= 0; i--) {
if (ind[C[i]] != -1)
nearest[i] = ind[C[i]];
ind[C[i]] = i;
}
memo.assign(C.size(), -1);
ll ans = f(0);
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD 1000000007
int N;
vector<int> C;
vector<int> memo;
vector<int> nearest;
vector<int> ind;
int f(int i) {
if (i >= nearest.size())
return 1;
if (memo[i] != -1)
return memo[i];
if (nearest[i] == -1) {
return memo[i] = f(i + 1) % MOD;
} else {
return memo[i] = (f(nearest[i]) + f(i + 1)) % MOD;
}
}
int main() {
cin >> N;
C.resize(N);
for (auto &e : C)
cin >> e;
C.erase(unique(C.begin(), C.end()), C.end());
ind.assign(200000 + 1, -1);
nearest.assign(C.size(), -1);
for (int i = C.size() - 1; i >= 0; i--) {
if (ind[C[i]] != -1)
nearest[i] = ind[C[i]];
ind[C[i]] = i;
}
memo.assign(C.size(), -1);
ll ans = f(0);
cout << ans << endl;
}
| [
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change",
"expression.operation.binary.change"
] | 907,017 | 907,018 | u167988719 | cpp |
p03096 | #define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <bitset>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (auto i = a; i < b; i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) {
ll a = 1;
while (p > 0) {
if (p % 2 == 0) {
x *= x;
p /= 2;
} else {
a *= x;
p--;
}
}
return a;
}
ll mpower(ll x, ll p) {
ll a = 1;
while (p > 0) {
if (p % 2 == 0) {
x = x * x % mod;
p /= 2;
} else {
a = a * x % mod;
p--;
}
}
return a;
}
ll c(ll n, ll k) {
ll a = 1;
rep(i, 1, k) {
a *= n - i + 1;
a /= i;
}
return a;
}
ll mc(ll n, ll m) {
ll k = 1, l = 1;
rep(i, n - m + 1, n + 1) k = k * i % mod;
rep(i, 1, m + 1) l = l * i % mod;
l = mpower(l, mod - 2);
return k * l % mod;
}
ll dp[200001], last[200001];
int main(void) {
int n;
cin >> n;
vector<int> c(n + 1);
rep(i, 1, n + 1) cin >> c[i];
dp[0] = 1;
rep(i, 1, n + 1) {
dp[i] = dp[i - 1];
if (last[c[i]] && last[c[i]] != i - 1) {
dp[i] += dp[c[i]];
dp[i] %= mod;
}
last[c[i]] = i;
}
printf("%lld\n", dp[n]);
return 0;
}
| #define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <bitset>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (auto i = a; i < b; i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) {
ll a = 1;
while (p > 0) {
if (p % 2 == 0) {
x *= x;
p /= 2;
} else {
a *= x;
p--;
}
}
return a;
}
ll mpower(ll x, ll p) {
ll a = 1;
while (p > 0) {
if (p % 2 == 0) {
x = x * x % mod;
p /= 2;
} else {
a = a * x % mod;
p--;
}
}
return a;
}
ll c(ll n, ll k) {
ll a = 1;
rep(i, 1, k) {
a *= n - i + 1;
a /= i;
}
return a;
}
ll mc(ll n, ll m) {
ll k = 1, l = 1;
rep(i, n - m + 1, n + 1) k = k * i % mod;
rep(i, 1, m + 1) l = l * i % mod;
l = mpower(l, mod - 2);
return k * l % mod;
}
ll dp[200001], last[200001];
int main(void) {
int n;
cin >> n;
vector<int> c(n + 1);
rep(i, 1, n + 1) cin >> c[i];
dp[0] = 1;
rep(i, 1, n + 1) {
dp[i] = dp[i - 1];
if (last[c[i]] && last[c[i]] != i - 1) {
dp[i] += dp[last[c[i]]];
dp[i] %= mod;
}
last[c[i]] = i;
}
printf("%lld\n", dp[n]);
return 0;
}
| [] | 907,023 | 907,024 | u128572736 | cpp |
p03096 | #define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <bitset>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (auto i = a; i < b; i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) {
ll a = 1;
while (p > 0) {
if (p % 2 == 0) {
x *= x;
p /= 2;
} else {
a *= x;
p--;
}
}
return a;
}
ll mpower(ll x, ll p) {
ll a = 1;
while (p > 0) {
if (p % 2 == 0) {
x = x * x % mod;
p /= 2;
} else {
a = a * x % mod;
p--;
}
}
return a;
}
ll c(ll n, ll k) {
ll a = 1;
rep(i, 1, k) {
a *= n - i + 1;
a /= i;
}
return a;
}
ll mc(ll n, ll m) {
ll k = 1, l = 1;
rep(i, n - m + 1, n + 1) k = k * i % mod;
rep(i, 1, m + 1) l = l * i % mod;
l = mpower(l, mod - 2);
return k * l % mod;
}
ll dp[20001], last[20001];
int main(void) {
int n;
cin >> n;
vector<int> c(n + 1);
rep(i, 1, n + 1) cin >> c[i];
dp[0] = 1;
rep(i, 1ll, n + 1) {
dp[i] = dp[i - 1];
if (last[c[i]] && last[c[i]] != i - 1) {
dp[i] += dp[c[i]];
dp[i] %= mod;
}
last[c[i]] = i;
}
printf("%lld\n", dp[n]);
return 0;
}
| #define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <bitset>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (auto i = a; i < b; i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) {
ll a = 1;
while (p > 0) {
if (p % 2 == 0) {
x *= x;
p /= 2;
} else {
a *= x;
p--;
}
}
return a;
}
ll mpower(ll x, ll p) {
ll a = 1;
while (p > 0) {
if (p % 2 == 0) {
x = x * x % mod;
p /= 2;
} else {
a = a * x % mod;
p--;
}
}
return a;
}
ll c(ll n, ll k) {
ll a = 1;
rep(i, 1, k) {
a *= n - i + 1;
a /= i;
}
return a;
}
ll mc(ll n, ll m) {
ll k = 1, l = 1;
rep(i, n - m + 1, n + 1) k = k * i % mod;
rep(i, 1, m + 1) l = l * i % mod;
l = mpower(l, mod - 2);
return k * l % mod;
}
ll dp[200001], last[200001];
int main(void) {
int n;
cin >> n;
vector<int> c(n + 1);
rep(i, 1, n + 1) cin >> c[i];
dp[0] = 1;
rep(i, 1, n + 1) {
dp[i] = dp[i - 1];
if (last[c[i]] && last[c[i]] != i - 1) {
dp[i] += dp[last[c[i]]];
dp[i] %= mod;
}
last[c[i]] = i;
}
printf("%lld\n", dp[n]);
return 0;
}
| [
"literal.number.change",
"variable_declaration.array_dimensions.change",
"call.arguments.change"
] | 907,025 | 907,024 | u128572736 | cpp |
p03096 | //高知能系Vtuberの高井茅乃です。
// Twitter: https://twitter.com/takaichino
// YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INTINF 1999999999
#define REP(i, n) for (int i = 0; i < n; i++)
#define REP1(i, n) for (int i = 1; i <= n; i++)
#define MODA 1000000007
//つねに10億7などの剰余をとる構造体
//参考: https://www.youtube.com/watch?v=L8grWxBlIZ4&t=9858
//参考:
//https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a#4-%E7%B4%AF%E4%B9%97-an
int mod = MODA;
struct modint {
ll x;
modint(ll x) : x(x % mod) {}
modint &operator+=(const modint a) {
(x += a.x) %= mod;
return *this;
}
modint &operator-=(const modint a) {
(x -= a.x) %= mod;
if (x < 0)
x += mod;
return *this;
}
modint &operator*=(const modint a) {
(x *= a.x) %= mod;
return *this;
}
modint &operator/=(modint a) {
ll exp = mod - 2;
while (exp > 0) {
if (exp & 1)
*this *= a.x;
a *= a.x;
exp >>= 1;
}
return *this;
}
modint operator+(const modint a) const {
modint res(*this);
return res += a;
}
modint operator-(const modint a) const {
modint res(*this);
return res -= a;
}
modint operator*(const modint a) const {
modint res(*this);
return res *= a;
}
modint operator/(const modint a) const {
modint res(*this);
return res /= a;
}
};
modint modpow(modint x, ll n) {
modint res = 1;
while (n > 0) {
if (n & 1)
res = res * x.x;
x = x * x;
n >>= 1;
}
return res;
}
int main() {
modint ans = 1;
int tmp;
int n;
cin >> n;
vector<pair<int, ll>> lo(n + 1);
REP(i, n + 1) lo[i] = make_pair(-1, (ll)0);
int prec = 0, c;
REP(i, n) {
cin >> c;
if (lo[c].first != i - 1 && lo[c].first != -1)
ans += lo[c].second;
lo[c] = make_pair(i, ans.x);
}
cout << ans.x << endl;
} | //高知能系Vtuberの高井茅乃です。
// Twitter: https://twitter.com/takaichino
// YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INTINF 1999999999
#define REP(i, n) for (int i = 0; i < n; i++)
#define REP1(i, n) for (int i = 1; i <= n; i++)
#define MODA 1000000007
//つねに10億7などの剰余をとる構造体
//参考: https://www.youtube.com/watch?v=L8grWxBlIZ4&t=9858
//参考:
//https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a#4-%E7%B4%AF%E4%B9%97-an
int mod = MODA;
struct modint {
ll x;
modint(ll x) : x(x % mod) {}
modint &operator+=(const modint a) {
(x += a.x) %= mod;
return *this;
}
modint &operator-=(const modint a) {
(x -= a.x) %= mod;
if (x < 0)
x += mod;
return *this;
}
modint &operator*=(const modint a) {
(x *= a.x) %= mod;
return *this;
}
modint &operator/=(modint a) {
ll exp = mod - 2;
while (exp > 0) {
if (exp & 1)
*this *= a.x;
a *= a.x;
exp >>= 1;
}
return *this;
}
modint operator+(const modint a) const {
modint res(*this);
return res += a;
}
modint operator-(const modint a) const {
modint res(*this);
return res -= a;
}
modint operator*(const modint a) const {
modint res(*this);
return res *= a;
}
modint operator/(const modint a) const {
modint res(*this);
return res /= a;
}
};
modint modpow(modint x, ll n) {
modint res = 1;
while (n > 0) {
if (n & 1)
res = res * x.x;
x = x * x;
n >>= 1;
}
return res;
}
int main() {
modint ans = 1;
int tmp;
int n;
cin >> n;
vector<pair<int, ll>> lo(200001);
REP(i, 200001) lo[i] = make_pair(-1, (ll)0);
int prec = 0, c;
REP(i, n) {
cin >> c;
if (lo[c].first != i - 1 && lo[c].first != -1)
ans += lo[c].second;
lo[c] = make_pair(i, ans.x);
}
cout << ans.x << endl;
} | [
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change",
"expression.operation.binary.change",
"expression.operation.binary.remove",
"assignment.variable.change"
] | 907,033 | 907,034 | u450007962 | cpp |
p03096 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
ll mod = 1e9 + 7;
int main() {
ll n;
cin >> n;
vector<ll> a(n), ls(n + 1, -1);
for (int i = 0; i < n; i++)
cin >> a[i];
vector<ll> dp(n);
dp[0] = 1;
ls[a[0]] = 0;
for (int i = 1; i < n; i++) {
ll inx = ls[a[i]];
if (inx == -1 || inx == i - 1) {
ls[a[i]] = i;
dp[i] = dp[i - 1];
// cout<<dp[i]<<endl;
continue;
}
dp[i] = (dp[inx] + dp[i - 1]) % mod;
// cout<<dp[i]<<endl;
ls[a[i]] = i;
}
cout << dp[n - 1] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
ll mod = 1e9 + 7;
int main() {
ll n;
cin >> n;
vector<ll> a(200005), ls(200005, -1);
for (int i = 0; i < n; i++)
cin >> a[i];
vector<ll> dp(200005);
dp[0] = 1;
ls[a[0]] = 0;
for (int i = 1; i < n; i++) {
ll inx = ls[a[i]];
if (inx == -1 || inx == i - 1) {
ls[a[i]] = i;
dp[i] = dp[i - 1];
// cout<<dp[i]<<endl;
continue;
}
dp[i] = (dp[inx] + dp[i - 1]) % mod;
// cout<<dp[i]<<endl;
ls[a[i]] = i;
}
cout << dp[n - 1] << endl;
return 0;
} | [
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change",
"expression.operation.binary.change",
"expression.operation.binary.remove"
] | 907,039 | 907,040 | u429261574 | cpp |
p03096 | #include <stdint.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
using default_counter_t = int64_t;
// macro
#define let auto const &
#define overload4(a, b, c, d, name, ...) name
#define rep1(n) \
for (default_counter_t i = 0, end_i = default_counter_t(n); i < end_i; ++i)
#define rep2(i, n) \
for (default_counter_t i = 0, end_##i = default_counter_t(n); i < end_##i; \
++i)
#define rep3(i, a, b) \
for (default_counter_t i = default_counter_t(a), \
end_##i = default_counter_t(b); \
i < end_##i; ++i)
#define rep4(i, a, b, c) \
for (default_counter_t i = default_counter_t(a), \
end_##i = default_counter_t(b); \
i < end_##i; i += default_counter_t(c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) \
for (default_counter_t i = default_counter_t(n) - 1; i >= 0; --i)
#define rrep2(i, n) \
for (default_counter_t i = default_counter_t(n) - 1; i >= 0; --i)
#define rrep3(i, a, b) \
for (default_counter_t i = default_counter_t(b) - 1, \
begin_##i = default_counter_t(a); \
i >= begin_##i; --i)
#define rrep4(i, a, b, c) \
for (default_counter_t \
i = (default_counter_t(b) - default_counter_t(a) - 1) / \
default_counter_t(c) * default_counter_t(c) + \
default_counter_t(a), \
begin_##i = default_counter_t(a); \
i >= begin_##i; i -= default_counter_t(c))
#define rrep(...) \
overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define ALL(f, c, ...) \
(([&](decltype((c)) cccc) { \
return (f)(std::begin(cccc), std::end(cccc), ##__VA_ARGS__); \
})(c))
// function
template <class C> constexpr C &Sort(C &a) {
std::sort(std::begin(a), std::end(a));
return a;
}
template <class C> constexpr auto &Min(C const &a) {
return *std::min_element(std::begin(a), std::end(a));
}
template <class C> constexpr auto &Max(C const &a) {
return *std::max_element(std::begin(a), std::end(a));
}
template <class C> constexpr auto Total(C const &c) {
return std::accumulate(std::begin(c), std::end(c), C(0));
}
template <typename T> auto CumSum(std::vector<T> const &v) {
std::vector<T> a(v.size() + 1, T(0));
for (std::size_t i = 0; i < a.size() - size_t(1); ++i)
a[i + 1] = a[i] + v[i];
return a;
}
template <typename T> constexpr bool ChMax(T &a, T const &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> constexpr bool ChMin(T &a, T const &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
void In(void) { return; }
template <typename First, typename... Rest>
void In(First &first, Rest &...rest) {
cin >> first;
In(rest...);
return;
}
template <class T, typename I> void VectorIn(vector<T> &v, const I n) {
v.resize(size_t(n));
rep(i, v.size()) cin >> v[i];
}
void Out(void) {
cout << "\n";
return;
}
template <typename First, typename... Rest>
void Out(First first, Rest... rest) {
cout << first << " ";
Out(rest...);
return;
}
constexpr auto yes(const bool c) { return c ? "yes" : "no"; }
constexpr auto Yes(const bool c) { return c ? "Yes" : "No"; }
constexpr auto YES(const bool c) { return c ? "YES" : "NO"; }
#ifdef USE_STACK_TRACE_LOGGER
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Weverything"
#include <glog/logging.h>
#pragma clang diagnostic pop
#endif //__clang__
#endif // USE_STACK_TRACE_LOGGER
signed main(int argc, char *argv[]) {
(void)argc;
#ifdef USE_STACK_TRACE_LOGGER
google::InitGoogleLogging(argv[0]);
google::InstallFailureSignalHandler();
#else
(void)argv;
#endif // USE_STACK_TRACE_LOGGER
int64_t N;
In(N);
vector<int64_t> C(N);
rep(i, N) {
In(C[i]);
C[i]--;
}
vector<int64_t> last(N, -1);
vector<int64_t> dp(N, 0);
dp[0] = 1;
last[C[0]] = 0;
rep(i, 1, N) {
int64_t tmp = 0;
if (last[C[i]] >= 0 && last[C[i]] < i - 1) {
tmp = dp[last[C[i]]];
}
last[C[i]] = i;
dp[i] = dp[i - 1] + tmp;
dp[i] %= 1000000007;
}
cout << dp[N - 1] << endl;
return EXIT_SUCCESS;
}
| #include <stdint.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
using default_counter_t = int64_t;
// macro
#define let auto const &
#define overload4(a, b, c, d, name, ...) name
#define rep1(n) \
for (default_counter_t i = 0, end_i = default_counter_t(n); i < end_i; ++i)
#define rep2(i, n) \
for (default_counter_t i = 0, end_##i = default_counter_t(n); i < end_##i; \
++i)
#define rep3(i, a, b) \
for (default_counter_t i = default_counter_t(a), \
end_##i = default_counter_t(b); \
i < end_##i; ++i)
#define rep4(i, a, b, c) \
for (default_counter_t i = default_counter_t(a), \
end_##i = default_counter_t(b); \
i < end_##i; i += default_counter_t(c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) \
for (default_counter_t i = default_counter_t(n) - 1; i >= 0; --i)
#define rrep2(i, n) \
for (default_counter_t i = default_counter_t(n) - 1; i >= 0; --i)
#define rrep3(i, a, b) \
for (default_counter_t i = default_counter_t(b) - 1, \
begin_##i = default_counter_t(a); \
i >= begin_##i; --i)
#define rrep4(i, a, b, c) \
for (default_counter_t \
i = (default_counter_t(b) - default_counter_t(a) - 1) / \
default_counter_t(c) * default_counter_t(c) + \
default_counter_t(a), \
begin_##i = default_counter_t(a); \
i >= begin_##i; i -= default_counter_t(c))
#define rrep(...) \
overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define ALL(f, c, ...) \
(([&](decltype((c)) cccc) { \
return (f)(std::begin(cccc), std::end(cccc), ##__VA_ARGS__); \
})(c))
// function
template <class C> constexpr C &Sort(C &a) {
std::sort(std::begin(a), std::end(a));
return a;
}
template <class C> constexpr auto &Min(C const &a) {
return *std::min_element(std::begin(a), std::end(a));
}
template <class C> constexpr auto &Max(C const &a) {
return *std::max_element(std::begin(a), std::end(a));
}
template <class C> constexpr auto Total(C const &c) {
return std::accumulate(std::begin(c), std::end(c), C(0));
}
template <typename T> auto CumSum(std::vector<T> const &v) {
std::vector<T> a(v.size() + 1, T(0));
for (std::size_t i = 0; i < a.size() - size_t(1); ++i)
a[i + 1] = a[i] + v[i];
return a;
}
template <typename T> constexpr bool ChMax(T &a, T const &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> constexpr bool ChMin(T &a, T const &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
void In(void) { return; }
template <typename First, typename... Rest>
void In(First &first, Rest &...rest) {
cin >> first;
In(rest...);
return;
}
template <class T, typename I> void VectorIn(vector<T> &v, const I n) {
v.resize(size_t(n));
rep(i, v.size()) cin >> v[i];
}
void Out(void) {
cout << "\n";
return;
}
template <typename First, typename... Rest>
void Out(First first, Rest... rest) {
cout << first << " ";
Out(rest...);
return;
}
constexpr auto yes(const bool c) { return c ? "yes" : "no"; }
constexpr auto Yes(const bool c) { return c ? "Yes" : "No"; }
constexpr auto YES(const bool c) { return c ? "YES" : "NO"; }
#ifdef USE_STACK_TRACE_LOGGER
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Weverything"
#include <glog/logging.h>
#pragma clang diagnostic pop
#endif //__clang__
#endif // USE_STACK_TRACE_LOGGER
signed main(int argc, char *argv[]) {
(void)argc;
#ifdef USE_STACK_TRACE_LOGGER
google::InitGoogleLogging(argv[0]);
google::InstallFailureSignalHandler();
#else
(void)argv;
#endif // USE_STACK_TRACE_LOGGER
int64_t N;
In(N);
vector<int64_t> C(N);
rep(i, N) {
In(C[i]);
C[i]--;
}
vector<int64_t> last(300000, -1);
vector<int64_t> dp(N, 0);
dp[0] = 1;
last[C[0]] = 0;
rep(i, 1, N) {
int64_t tmp = 0;
if (last[C[i]] >= 0 && last[C[i]] < i - 1) {
tmp = dp[last[C[i]]];
}
last[C[i]] = i;
dp[i] = dp[i - 1] + tmp;
dp[i] %= 1000000007;
}
cout << dp[N - 1] << endl;
return EXIT_SUCCESS;
}
| [
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change"
] | 907,048 | 907,049 | u653699618 | cpp |
p03096 | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
const int N = 300100;
const int MOD = (int)1e9 + 7;
int n, a[N], f[N], d[N];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
f[a[i]] = 0;
}
d[0] = 1;
for (int i = 1; i <= n; i++) {
d[i] = d[i - 1];
if (i > 1 && a[i] != a[i - 1]) {
d[i] += f[a[i]];
d[i] %= MOD;
}
f[a[i]] += d[i - 1];
f[a[i]] %= MOD;
}
printf("%d\n", d[n]);
return 0;
} | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
const int N = 300100;
const int MOD = (int)1e9 + 7;
int n, a[N], f[N], d[N];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
f[a[i]] = 0;
}
d[0] = 1;
for (int i = 1; i <= n; i++) {
d[i] = d[i - 1];
if (i == 0 || a[i] != a[i - 1]) {
d[i] += f[a[i]];
d[i] %= MOD;
f[a[i]] += d[i - 1];
f[a[i]] %= MOD;
}
}
printf("%d\n", d[n]);
return 0;
} | [
"control_flow.loop.for.condition.change"
] | 907,052 | 907,053 | u902910558 | cpp |
p03096 | // g++ -std=c++14 test.cpp -o test.out
#include <algorithm>
#include <bitset>
#include <cassert>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <utility>
#include <vector>
using namespace std;
#define LL long long int
const LL INF = (1LL << 60);
const int INF_INT = 2147483647 - 1e6 - 1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;
LL N;
LL C[200000];
LL ans = 1;
void solve() {
//ランレングス圧縮
vector<LL> C_pressed;
C_pressed.push_back(C[0]);
for (int i = 1; i < N; i++) {
if (C[i] != C[i - 1])
C_pressed.push_back(C[i]);
}
N = C_pressed.size();
// for(int i=0;i<N;i++) cout << C_pressed[i] << " ";
// cout << endl;
vector<LL> color_num(200001, 0);
color_num[C_pressed[0]]++;
vector<LL> dp(N, 0);
dp[0] = 1;
for (int i = 1; i < N; i++) {
dp[i] = dp[i - 1] + color_num[C_pressed[i]];
color_num[C_pressed[i]] += dp[i];
}
ans = dp[N - 1];
}
int main() {
cin >> N;
for (int i = 0; i < N; i++)
cin >> C[i];
solve();
cout << ans << endl;
return 0;
} | // g++ -std=c++14 test.cpp -o test.out
#include <algorithm>
#include <bitset>
#include <cassert>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <utility>
#include <vector>
using namespace std;
#define LL long long int
const LL INF = (1LL << 60);
const int INF_INT = 2147483647 - 1e6 - 1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;
LL N;
LL C[200000];
LL ans = 1;
void solve() {
//ランレングス圧縮
vector<LL> C_pressed;
C_pressed.push_back(C[0]);
for (int i = 1; i < N; i++) {
if (C[i] != C[i - 1])
C_pressed.push_back(C[i]);
}
N = C_pressed.size();
// for(int i=0;i<N;i++) cout << C_pressed[i] << " ";
// cout << endl;
vector<LL> color_num(200001, 0);
color_num[C_pressed[0]]++;
vector<LL> dp(N, 0);
dp[0] = 1;
for (int i = 1; i < N; i++) {
dp[i] = (dp[i - 1] + color_num[C_pressed[i]]) % mod;
color_num[C_pressed[i]] = dp[i];
}
// for(int i=0;i<N;i++) cout << dp[i] << " ";
// cout << endl;
ans = dp[N - 1];
}
int main() {
cin >> N;
for (int i = 0; i < N; i++)
cin >> C[i];
solve();
cout << ans << endl;
return 0;
} | [
"assignment.change",
"assignment.value.change"
] | 907,063 | 907,062 | u302000346 | cpp |
p03096 | #pragma region
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s)-1; (i) >= 0; --(i))
#define all(x) x.begin(), x.end()
#pragma endregion
int main() {
int n;
cin >> n;
vector<vector<int>> pos(n + 1);
vector<ll> dp(n + 1);
dp[0] = 1;
int pre = 0;
rep(i, n) {
int a;
cin >> a;
dp[i + 1] = dp[i];
if (pre != a && pos[a].size() != 0) {
dp[i + 1] += dp[pos[a].back() + 1];
}
dp[i + 1] %= (ll)1e9 + 7;
pos[a].push_back(i);
pre = a;
}
cout << dp[n] << endl;
} | #pragma region
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s)-1; (i) >= 0; --(i))
#define all(x) x.begin(), x.end()
#pragma endregion
int main() {
int n;
cin >> n;
vector<vector<int>> pos(200005);
vector<ll> dp(n + 1);
dp[0] = 1;
int pre = 0;
rep(i, n) {
int a;
cin >> a;
dp[i + 1] = dp[i];
if (pre != a && pos[a].size() != 0) {
dp[i + 1] += dp[pos[a].back() + 1];
}
dp[i + 1] %= (ll)1e9 + 7;
pos[a].push_back(i);
pre = a;
}
cout << dp[n] << endl;
} | [
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change",
"expression.operation.binary.change",
"expression.operation.binary.remove"
] | 907,076 | 907,077 | u521389909 | cpp |
p03096 | #include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
int main(void) {
int n, i, t, c, dp[200003] = {};
const int mod = 1e9 + 7;
vector<int> cv;
map<int, ll> m;
cv.push_back(0);
t = 1;
cin >> n;
for (i = 0; i < n; i++) {
cin >> c;
if (c != cv[t - 1]) {
cv.push_back(c);
t++;
}
}
dp[0] = 1;
m[0] = 1;
for (i = 0; i < t; i++) {
dp[i] = m[cv[i]];
m[cv[i]] = (m[cv[i - 1]] + dp[i]) % mod;
}
cout << dp[t - 1] + 1 << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
int main(void) {
int n, i, t, c, dp[200003] = {};
const int mod = 1e9 + 7;
vector<int> cv;
map<int, int> m;
cv.push_back(0);
t = 1;
cin >> n;
for (i = 0; i < n; i++) {
cin >> c;
if (c != cv[t - 1]) {
cv.push_back(c);
t++;
}
}
dp[0] = 1;
m[0] = 1;
for (i = 0; i < t; i++) {
dp[i] = m[cv[i]];
m[cv[i + 1]] = (m[cv[i + 1]] + dp[i]) % mod;
}
cout << dp[t - 1] << endl;
return 0;
} | [
"assignment.change",
"misc.opposites",
"expression.operator.arithmetic.change",
"assignment.value.change",
"variable_access.subscript.index.change",
"expression.operation.binary.change",
"expression.operation.binary.remove"
] | 907,080 | 907,081 | u088895504 | cpp |
p03096 | #include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;
typedef int64_t ll;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
const int INF = 1001001001;
const ll INFL = (1LL << 60);
const double eps = (1e-9);
const ll mod = 1e9 + 7;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<ll> c(n);
rep(i, n) cin >> c[i];
vector<ll> sum(n, 0);
vector<ll> dp(n + 1, 0);
dp[0] = 1;
rep(i, n) {
ll x = c[i];
if (i != 0 && c[i] == c[i - 1]) {
dp[i + 1] = dp[i];
continue; // 同じ値の間には区切りを入れない
}
sum[x] = (sum[x] + dp[i]) % mod;
dp[i + 1] = sum[x];
}
cout << dp[n] << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;
typedef int64_t ll;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
const int INF = 1001001001;
const ll INFL = (1LL << 60);
const double eps = (1e-9);
const ll mod = 1e9 + 7;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<ll> c(n);
rep(i, n) cin >> c[i];
vector<ll> sum(2e5 + 5, 0);
vector<ll> dp(n + 1, 0);
dp[0] = 1;
rep(i, n) {
ll x = c[i];
if (i != 0 && c[i] == c[i - 1]) {
dp[i + 1] = dp[i];
continue; // 同じ値の間には区切りを入れない
}
sum[x] = (sum[x] + dp[i]) % mod;
dp[i + 1] = sum[x];
}
cout << dp[n] << endl;
return 0;
}
| [
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change"
] | 907,084 | 907,085 | u733814820 | cpp |
p03096 | #include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#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)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
int main() {
int N;
cin >> N;
int last[202020];
ll dp[202020] = {};
rep(i, N) { last[i] = -1; }
dp[0] = 1;
for (int i = 0; i <= N - 1; i++) {
int a;
cin >> a;
a--;
if (i == 0) {
last[a] = i;
continue;
}
if (last[a] != -1 && last[a] != i - 1)
dp[i] = dp[i - 1] + dp[last[a]];
else
dp[i] = dp[i - 1];
dp[i] %= mod;
// cout << dp[i] << endl;
// cout << last[a] << endl;
last[a] = i;
}
cout << dp[N - 1] << endl;
} | #include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#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)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
int main() {
int N;
cin >> N;
int last[202020];
ll dp[202020] = {};
rep(i, 202020) { last[i] = -1; }
dp[0] = 1;
for (int i = 0; i <= N - 1; i++) {
int a;
cin >> a;
a--;
if (i == 0) {
last[a] = i;
continue;
}
if (last[a] != -1 && last[a] != i - 1)
dp[i] = dp[i - 1] + dp[last[a]];
else
dp[i] = dp[i - 1];
dp[i] %= mod;
// cout << dp[i] << endl;
// cout << last[a] << endl;
last[a] = i;
}
cout << dp[N - 1] << endl;
}
| [] | 907,086 | 907,087 | u841131859 | cpp |
p03096 | #include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#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)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
int main() {
int N;
cin >> N;
int last[202020];
int dp[202020] = {};
rep(i, N) { last[i] = -1; }
dp[0] = 1;
for (int i = 0; i <= N - 1; i++) {
int a;
cin >> a;
a--;
if (i == 0) {
last[a] = i;
continue;
}
if (last[a] != -1 && last[a] != i - 1)
dp[i] = dp[i - 1] + dp[last[a]];
else
dp[i] = dp[i - 1];
dp[i] %= mod;
// cout << dp[i] << endl;
// cout << last[a] << endl;
last[a] = i;
}
cout << dp[N - 1] << endl;
} | #include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#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)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
int main() {
int N;
cin >> N;
int last[202020];
ll dp[202020] = {};
rep(i, 202020) { last[i] = -1; }
dp[0] = 1;
for (int i = 0; i <= N - 1; i++) {
int a;
cin >> a;
a--;
if (i == 0) {
last[a] = i;
continue;
}
if (last[a] != -1 && last[a] != i - 1)
dp[i] = dp[i - 1] + dp[last[a]];
else
dp[i] = dp[i - 1];
dp[i] %= mod;
// cout << dp[i] << endl;
// cout << last[a] << endl;
last[a] = i;
}
cout << dp[N - 1] << endl;
}
| [
"variable_declaration.type.change"
] | 907,088 | 907,087 | u841131859 | cpp |
p03096 | #include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#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)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
int main() {
int N;
cin >> N;
int last[N];
int dp[N] = {};
rep(i, N) { last[i] = -1; }
dp[0] = 1;
for (int i = 0; i <= N - 1; i++) {
int a;
cin >> a;
a--;
if (i == 0) {
last[a] = i;
continue;
}
if (last[a] != -1 && last[a] != i - 1)
dp[i] = dp[i - 1] + dp[last[a]];
else
dp[i] = dp[i - 1];
dp[i] %= mod;
// cout << dp[i] << endl;
// cout << last[a] << endl;
last[a] = i;
}
cout << dp[N - 1] << endl;
}
| #include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#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)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
int main() {
int N;
cin >> N;
int last[202020];
ll dp[202020] = {};
rep(i, 202020) { last[i] = -1; }
dp[0] = 1;
for (int i = 0; i <= N - 1; i++) {
int a;
cin >> a;
a--;
if (i == 0) {
last[a] = i;
continue;
}
if (last[a] != -1 && last[a] != i - 1)
dp[i] = dp[i - 1] + dp[last[a]];
else
dp[i] = dp[i - 1];
dp[i] %= mod;
// cout << dp[i] << endl;
// cout << last[a] << endl;
last[a] = i;
}
cout << dp[N - 1] << endl;
}
| [
"identifier.replace.remove",
"literal.replace.add",
"variable_declaration.array_dimensions.change",
"variable_declaration.type.change"
] | 907,089 | 907,087 | u841131859 | cpp |
p03096 | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) \
for (int i = (n); i >= (k); i--) \
;
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template <class T> istream &operator>>(istream &is, vector<T> &v) {
for (auto &elemnt : v)
is >> elemnt;
return is;
}
template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) {
is >> p.first >> p.second;
return is;
}
template <class T> vector<T> make_vector(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vector(size_t a, Ts... ts) {
return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));
}
const int MOD = 1e9 + 7;
const int INF = 2e18;
template <int mod> struct ModInt {
int x;
ModInt() : x(0) {}
ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
ModInt &operator+=(const ModInt &p) {
if ((x += p.x) >= mod)
x -= mod;
return *this;
}
ModInt &operator-=(const ModInt &p) {
if ((x += mod - p.x) >= mod)
x -= mod;
return *this;
}
ModInt &operator*=(const ModInt &p) {
x = (int)(1LL * x * p.x % mod);
return *this;
}
ModInt &operator/=(const ModInt &p) {
*this *= p.inverse();
return *this;
}
ModInt operator-() const { return ModInt(-x); }
ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
bool operator==(const ModInt &p) const { return x == p.x; }
bool operator!=(const ModInt &p) const { return x != p.x; }
ModInt inverse() const {
int a = x, b = mod, u = 1, v = 0, t;
while (b > 0) {
t = a / b;
swap(a -= t * b, b);
swap(u -= t * v, v);
}
return ModInt(u);
}
ModInt pow(int64_t n) const {
ModInt ret(1), mul(x);
while (n > 0) {
if (n & 1)
ret *= mul;
mul *= mul;
n >>= 1;
}
return ret;
}
friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }
friend istream &operator>>(istream &is, ModInt &a) {
int64_t t;
is >> t;
a = ModInt<mod>(t);
return (is);
}
static int get_mod() { return mod; }
};
using modint = ModInt<MOD>;
signed main() {
int N;
cin >> N;
vector<int> C(1);
cin >> C;
vector<set<int>> idx(N + 1);
for (int i = 1; i < N; i++) {
int temp;
cin >> temp;
if (*C.rbegin() != temp)
C.push_back(temp);
idx[temp].insert(C.size() - 1);
}
vector<modint> ans(C.size(), 1);
for (int i = C.size() - 2; i >= 0; i--) {
auto itr = idx[C[i]].upper_bound(i);
if (itr == idx[C[i]].end())
ans[i] = ans[i + 1];
else
ans[i] = ans[i + 1] + ans[*itr];
}
cout << ans[0] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) \
for (int i = (n); i >= (k); i--) \
;
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template <class T> istream &operator>>(istream &is, vector<T> &v) {
for (auto &elemnt : v)
is >> elemnt;
return is;
}
template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) {
is >> p.first >> p.second;
return is;
}
template <class T> vector<T> make_vector(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vector(size_t a, Ts... ts) {
return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));
}
const int MOD = 1e9 + 7;
const int INF = 2e18;
template <int mod> struct ModInt {
int x;
ModInt() : x(0) {}
ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
ModInt &operator+=(const ModInt &p) {
if ((x += p.x) >= mod)
x -= mod;
return *this;
}
ModInt &operator-=(const ModInt &p) {
if ((x += mod - p.x) >= mod)
x -= mod;
return *this;
}
ModInt &operator*=(const ModInt &p) {
x = (int)(1LL * x * p.x % mod);
return *this;
}
ModInt &operator/=(const ModInt &p) {
*this *= p.inverse();
return *this;
}
ModInt operator-() const { return ModInt(-x); }
ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
bool operator==(const ModInt &p) const { return x == p.x; }
bool operator!=(const ModInt &p) const { return x != p.x; }
ModInt inverse() const {
int a = x, b = mod, u = 1, v = 0, t;
while (b > 0) {
t = a / b;
swap(a -= t * b, b);
swap(u -= t * v, v);
}
return ModInt(u);
}
ModInt pow(int64_t n) const {
ModInt ret(1), mul(x);
while (n > 0) {
if (n & 1)
ret *= mul;
mul *= mul;
n >>= 1;
}
return ret;
}
friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }
friend istream &operator>>(istream &is, ModInt &a) {
int64_t t;
is >> t;
a = ModInt<mod>(t);
return (is);
}
static int get_mod() { return mod; }
};
using modint = ModInt<MOD>;
signed main() {
int N;
cin >> N;
vector<int> C(1);
cin >> C;
vector<set<int>> idx(200100);
for (int i = 1; i < N; i++) {
int temp;
cin >> temp;
if (*C.rbegin() != temp)
C.push_back(temp);
idx[temp].insert(C.size() - 1);
}
vector<modint> ans(C.size(), 1);
for (int i = C.size() - 2; i >= 0; i--) {
auto itr = idx[C[i]].upper_bound(i);
if (itr == idx[C[i]].end())
ans[i] = ans[i + 1];
else
ans[i] = ans[i + 1] + ans[*itr];
}
cout << ans[0] << endl;
}
| [
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change",
"expression.operation.binary.change",
"expression.operation.binary.remove"
] | 907,092 | 907,091 | u714538557 | cpp |
p03096 | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#define _USE_MATH_DEFINES
#include <functional>
#include <math.h>
using namespace std;
#define rep(i, x) for (ll i = 0; i < x; i++)
#define repn(i, x) for (ll i = 1; i <= x; i++)
typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;
ll max(ll a, ll b) {
if (a > b) {
return a;
}
return b;
}
ll min(ll a, ll b) {
if (a > b) {
return b;
}
return a;
}
ll gcd(ll a, ll b) {
if (b == 0) {
return a;
}
if (a < b) {
return gcd(b, a);
}
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
struct edge {
ll ind;
ll fr;
ll to;
ll d;
};
///////////////////////////
int main() {
ll N;
cin >> N;
vector<ll> C(N + 1);
repn(i, N) cin >> C[i];
vector<ll> pre(N + 1, -1), dp(N + 1, 0);
dp[0] = 1;
repn(i, N) {
dp[i] = dp[i - 1];
if (pre[C[i]] != -1 && pre[C[i]] != i - 1) {
dp[i] += dp[pre[C[i]]];
}
pre[C[i]] = i;
dp[i] %= MOD;
// cout << dp[i] << endl;
}
cout << dp[N];
system("PAUSE");
}
| #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#define _USE_MATH_DEFINES
#include <functional>
#include <math.h>
using namespace std;
#define rep(i, x) for (ll i = 0; i < x; i++)
#define repn(i, x) for (ll i = 1; i <= x; i++)
typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;
ll max(ll a, ll b) {
if (a > b) {
return a;
}
return b;
}
ll min(ll a, ll b) {
if (a > b) {
return b;
}
return a;
}
ll gcd(ll a, ll b) {
if (b == 0) {
return a;
}
if (a < b) {
return gcd(b, a);
}
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
struct edge {
ll ind;
ll fr;
ll to;
ll d;
};
///////////////////////////
int main() {
ll N;
cin >> N;
vector<ll> C(N + 1);
repn(i, N) cin >> C[i];
vector<ll> pre(300000, -1), dp(N + 1, 0);
dp[0] = 1;
repn(i, N) {
dp[i] = dp[i - 1];
if (pre[C[i]] != -1 && pre[C[i]] != i - 1) {
dp[i] += dp[pre[C[i]]];
}
pre[C[i]] = i;
dp[i] %= MOD;
// cout << dp[i] << endl;
}
cout << dp[N];
system("PAUSE");
}
| [
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change",
"expression.operation.binary.change",
"expression.operation.binary.remove"
] | 907,093 | 907,094 | u004411048 | cpp |
p03096 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll, ll> pll;
ll mod = 1e9 + 7;
int main() {
ll n;
cin >> n;
vec c(n);
for (ll i = 0; i < n; i++) {
cin >> c[i];
}
vec dp(n + 1);
vec left(2e5 + 1, -1);
dp[0] = 1;
for (ll i = 0; i < n; i++) {
dp[i + 1] = dp[i];
ll tc = c[i];
if (left[tc] > -1 && left[tc] < i - 1)
dp[i + 1] = (dp[i + 1] + dp[left[tc + 1]]) % mod;
left[tc] = i;
}
cout << dp[n] << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll, ll> pll;
ll mod = 1e9 + 7;
int main() {
ll n;
cin >> n;
vec c(n);
for (ll i = 0; i < n; i++) {
cin >> c[i];
}
vec dp(n + 1);
vec left(2e5 + 1, -1);
dp[0] = 1;
for (ll i = 0; i < n; i++) {
dp[i + 1] = dp[i];
ll tc = c[i];
if (left[tc] > -1 && left[tc] < i - 1)
dp[i + 1] = (dp[i + 1] + dp[left[tc] + 1]) % mod;
left[tc] = i;
}
cout << dp[n] << endl;
} | [] | 907,095 | 907,096 | u718758485 | cpp |
p03096 | #include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
uint32_t n;
cin >> n;
vector<uint32_t> cs(n);
for (uint32_t i = 0; i < n; i++) {
cin >> cs[i];
}
vector<uint64_t> vals(n);
vector<uint32_t> marks(n + 1, -1); // 1 origin, idx: c, elem : idx
vals[0] = 1;
marks[cs[0]] = 0;
for (uint32_t i = 1; i < n; i++) {
// cout << i << " " << vals[i - 1] << endl;
uint32_t c = cs[i];
if (c == cs[i - 1]) {
vals[i] = vals[i - 1];
continue;
}
uint32_t &cur_mark = marks[c];
if (cur_mark != -1) {
vals[i] = vals[i - 1] + vals[cur_mark];
vals[i] %= 1000000007;
} else {
vals[i] = vals[i - 1];
}
// cout << i << " " << c << " " << vals[i] << endl;
cur_mark = i;
}
cout << vals[n - 1] << endl;
return 0;
}
| #include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
uint32_t n;
cin >> n;
vector<uint32_t> cs(n);
for (uint32_t i = 0; i < n; i++) {
cin >> cs[i];
}
vector<uint64_t> vals(n);
vector<uint32_t> marks(200001, -1); // 1 origin, idx: c, elem : idx
vals[0] = 1;
marks[cs[0]] = 0;
for (uint32_t i = 1; i < n; i++) {
// cout << i << " " << vals[i - 1] << endl;
uint32_t c = cs[i];
if (c == cs[i - 1]) {
vals[i] = vals[i - 1];
continue;
}
uint32_t &cur_mark = marks[c];
if (cur_mark != -1) {
vals[i] = vals[i - 1] + vals[cur_mark];
vals[i] %= 1000000007;
} else {
vals[i] = vals[i - 1];
}
// cout << i << " " << c << " " << vals[i] << endl;
cur_mark = i;
}
cout << vals[n - 1] << endl;
return 0;
}
| [
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change",
"expression.operation.binary.change",
"expression.operation.binary.remove"
] | 907,097 | 907,098 | u862095327 | cpp |
p03096 | #include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;
template <uint_fast64_t MOD> class ModInt {
using u64 = uint_fast64_t;
public:
u64 a;
ModInt(const u64 x = 0) : a(x % MOD) {}
constexpr u64 &value() { return a; }
constexpr ModInt operator-() { return a ? MOD - a : 0; }
constexpr ModInt operator+(const ModInt rhs) { return ModInt(*this) += rhs; }
constexpr ModInt operator-(const ModInt rhs) { return ModInt(*this) -= rhs; }
constexpr ModInt operator*(const ModInt rhs) { return ModInt(*this) *= rhs; }
constexpr ModInt operator/(const ModInt rhs) { return ModInt(*this) /= rhs; }
constexpr ModInt &operator+=(const ModInt rhs) {
a += rhs.a;
if (a >= MOD) {
a -= MOD;
}
return *this;
}
constexpr ModInt &operator-=(const ModInt rhs) {
if (a < rhs.a) {
a += MOD;
}
a -= rhs.a;
return *this;
}
constexpr ModInt &operator*=(const ModInt rhs) {
a = a * rhs.a % MOD;
return *this;
}
constexpr ModInt &operator/=(const ModInt rhs) {
*this *= rhs.inv();
return *this;
}
constexpr bool operator==(const ModInt rhs) { return this->a == rhs.a; }
constexpr bool operator!=(const ModInt rhs) { return this->a != rhs.a; }
friend constexpr ostream &operator<<(ostream &os, const ModInt<MOD> &x) {
return os << x.a;
}
friend constexpr istream &operator>>(istream &is, ModInt<MOD> &x) {
return is >> x.a;
}
constexpr ModInt inv() {
u64 x = a, y = MOD, u = 1, v = 0, t = 0;
while (y > 0) {
t = x / y;
a -= t * y;
swap(x, y);
u -= t * v;
swap(u, v);
}
return ModInt(u);
}
constexpr ModInt pow(int e) {
u64 x = 1, p = a;
while (e > 0) {
if (e % 2 == 0) {
p = (p * p) % MOD;
e /= 2;
} else {
x = (x * p) % MOD;
e--;
}
}
return ModInt(x);
}
};
int main() {
using mint = ModInt<MOD>;
int N;
cin >> N;
vector<int> C(N);
rep(i, N) cin >> C[i];
vector<int> last(N + 1, -1);
vector<mint> dp(N + 1);
dp[0] = 1;
// dp[i]:=i個めまで使った時の通り数
for (int i = 0; i < N; i++) {
if (last[C[i]] != -1) {
if (last[C[i]] != i - 1)
dp[i + 1] = dp[i] + dp[last[C[i]] + 1];
else
dp[i + 1] = dp[i];
} else {
dp[i + 1] = dp[i];
}
last[C[i]] = i;
}
cout << dp[N] << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;
template <uint_fast64_t MOD> class ModInt {
using u64 = uint_fast64_t;
public:
u64 a;
ModInt(const u64 x = 0) : a(x % MOD) {}
constexpr u64 &value() { return a; }
constexpr ModInt operator-() { return a ? MOD - a : 0; }
constexpr ModInt operator+(const ModInt rhs) { return ModInt(*this) += rhs; }
constexpr ModInt operator-(const ModInt rhs) { return ModInt(*this) -= rhs; }
constexpr ModInt operator*(const ModInt rhs) { return ModInt(*this) *= rhs; }
constexpr ModInt operator/(const ModInt rhs) { return ModInt(*this) /= rhs; }
constexpr ModInt &operator+=(const ModInt rhs) {
a += rhs.a;
if (a >= MOD) {
a -= MOD;
}
return *this;
}
constexpr ModInt &operator-=(const ModInt rhs) {
if (a < rhs.a) {
a += MOD;
}
a -= rhs.a;
return *this;
}
constexpr ModInt &operator*=(const ModInt rhs) {
a = a * rhs.a % MOD;
return *this;
}
constexpr ModInt &operator/=(const ModInt rhs) {
*this *= rhs.inv();
return *this;
}
constexpr bool operator==(const ModInt rhs) { return this->a == rhs.a; }
constexpr bool operator!=(const ModInt rhs) { return this->a != rhs.a; }
friend constexpr ostream &operator<<(ostream &os, const ModInt<MOD> &x) {
return os << x.a;
}
friend constexpr istream &operator>>(istream &is, ModInt<MOD> &x) {
return is >> x.a;
}
constexpr ModInt inv() {
u64 x = a, y = MOD, u = 1, v = 0, t = 0;
while (y > 0) {
t = x / y;
a -= t * y;
swap(x, y);
u -= t * v;
swap(u, v);
}
return ModInt(u);
}
constexpr ModInt pow(int e) {
u64 x = 1, p = a;
while (e > 0) {
if (e % 2 == 0) {
p = (p * p) % MOD;
e /= 2;
} else {
x = (x * p) % MOD;
e--;
}
}
return ModInt(x);
}
};
int main() {
using mint = ModInt<MOD>;
int N;
cin >> N;
vector<int> C(N);
rep(i, N) cin >> C[i];
vector<int> last(200010, -1);
vector<mint> dp(N + 1);
dp[0] = 1;
// dp[i]:=i個めまで使った時の通り数
for (int i = 0; i < N; i++) {
if (last[C[i]] != -1) {
if (last[C[i]] != i - 1)
dp[i + 1] = dp[i] + dp[last[C[i]] + 1];
else
dp[i + 1] = dp[i];
} else {
dp[i + 1] = dp[i];
}
last[C[i]] = i;
}
cout << dp[N] << endl;
return 0;
} | [
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change",
"expression.operation.binary.change",
"expression.operation.binary.remove"
] | 907,099 | 907,100 | u917282863 | cpp |
p03096 | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;
const double PI = 3.14159265358979323846;
#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))
#define rep(i, N) for (int i = 0; i < N; ++i)
#define CEIL(x, y) (((x) + (y)-1) / (y))
#define MOD 1000000007ULL
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
int c, prev = 0;
vs32 pos(n + 1, -1);
vs64 dp(n + 1);
dp[0] = 1;
rep(i, n) {
cin >> c;
if (c == prev || pos[c] == -1) {
dp[i + 1] = dp[i];
} else {
dp[i + 1] = (dp[i] + dp[pos[c]]) % MOD;
}
pos[c] = i + 1;
prev = c;
}
cout << dp[n] << "\n";
return 0;
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;
const double PI = 3.14159265358979323846;
#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))
#define rep(i, N) for (int i = 0; i < N; ++i)
#define CEIL(x, y) (((x) + (y)-1) / (y))
#define MOD 1000000007ULL
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
int c, prev = 0;
vs32 pos(200000 + 1, -1);
vs64 dp(n + 1);
dp[0] = 1;
rep(i, n) {
cin >> c;
if (c == prev || pos[c] == -1) {
dp[i + 1] = dp[i];
} else {
dp[i + 1] = (dp[i] + dp[pos[c]]) % MOD;
}
pos[c] = i + 1;
prev = c;
}
cout << dp[n] << "\n";
return 0;
}
| [
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change",
"expression.operation.binary.change"
] | 907,107 | 907,108 | u806999568 | cpp |
p03096 | #include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif
using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
#define reps(i, S, E) for (ll i = (S); i <= (E); i++)
#define rep(i, N) reps(i, 0, N - 1)
#define deps(i, E, S) for (ll i = (E); i >= (S); i--)
#define dep(i, N) deps(i, N - 1, 0)
const ll INF = 1LL << 60;
const int INF_INT = 1 << 30;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
struct mll {
static ll MOD;
ll val;
mll(ll v = 0) : val(v % MOD) {
if (val < 0)
val += MOD;
}
mll operator-() const { return -val; }
mll operator+(const mll &b) const { return val + b.val; }
mll operator-(const mll &b) const { return val - b.val; }
mll operator*(const mll &b) const { return val * b.val; }
mll operator/(const mll &b) const { return mll(*this) /= b; }
mll operator+(ll b) const { return *this + mll(b); }
mll operator-(ll b) const { return *this - mll(b); }
mll operator*(ll b) const { return *this * mll(b); }
friend mll operator+(ll a, const mll &b) { return b + a; }
friend mll operator-(ll a, const mll &b) { return -b + a; }
friend mll operator*(ll a, const mll &b) { return b * a; }
mll &operator+=(const mll &b) {
val = (val + b.val) % MOD;
return *this;
}
mll &operator-=(const mll &b) {
val = (val + MOD - b.val) % MOD;
return *this;
}
mll &operator*=(const mll &b) {
val = (val * b.val) % MOD;
return *this;
}
mll &operator/=(const mll &b) {
ll c = b.val, d = MOD, u = 1, v = 0;
while (d) {
ll t = c / d;
c -= t * d;
swap(c, d);
u -= t * v;
swap(u, v);
}
val = val * u % MOD;
if (val < 0)
val += MOD;
return *this;
}
mll &operator+=(ll b) { return *this += mll(b); }
mll &operator-=(ll b) { return *this -= mll(b); }
mll &operator*=(ll b) { return *this *= mll(b); }
mll &operator/=(ll b) { return *this /= mll(b); }
bool operator==(const mll &b) { return val == b.val; }
bool operator!=(const mll &b) { return val != b.val; }
bool operator==(ll b) { return *this == mll(b); }
bool operator!=(ll b) { return *this != mll(b); }
friend bool operator==(ll a, const mll &b) { return mll(a) == b.val; }
friend bool operator!=(ll a, const mll &b) { return mll(a) != b.val; }
friend ostream &operator<<(ostream &os, const mll &a) { return os << a.val; }
friend istream &operator>>(istream &is, mll &a) { return is >> a.val; }
static mll Combination(ll a, ll b) {
chmin(b, a - b);
if (b < 0)
return mll(0);
mll c = 1;
rep(i, b) c *= a - i;
rep(i, b) c /= i + 1;
return c;
}
};
using vmll = std::vector<mll>;
using vvmll = std::vector<vmll>;
using vvvmll = std::vector<vvmll>;
using vvvvmll = std::vector<vvvmll>;
struct Fast {
Fast() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(std::numeric_limits<double>::max_digits10);
}
} fast; // cin,cout高速化のおまじない+桁数指定
ll mll::MOD = (ll)(1e9 + 7); // 998244353ll;
int main() {
ll N;
cin >> N;
vector<ll> C(N);
rep(i, N) { cin >> C[i]; }
vll prevC(N + 1, -1);
vmll dp(N, 0);
dp[0] = 1;
rep(i, N) {
if (i > 0) {
dp[i] += dp[i - 1];
if (prevC[C[i]] >= 0 && prevC[C[i]] + 1 < i) {
dp[i] += dp[prevC[C[i]]];
}
}
prevC[C[i]] = i;
}
cout << dp[N - 1] << endl;
return 0;
}
| #include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif
using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
#define reps(i, S, E) for (ll i = (S); i <= (E); i++)
#define rep(i, N) reps(i, 0, N - 1)
#define deps(i, E, S) for (ll i = (E); i >= (S); i--)
#define dep(i, N) deps(i, N - 1, 0)
const ll INF = 1LL << 60;
const int INF_INT = 1 << 30;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
struct mll {
static ll MOD;
ll val;
mll(ll v = 0) : val(v % MOD) {
if (val < 0)
val += MOD;
}
mll operator-() const { return -val; }
mll operator+(const mll &b) const { return val + b.val; }
mll operator-(const mll &b) const { return val - b.val; }
mll operator*(const mll &b) const { return val * b.val; }
mll operator/(const mll &b) const { return mll(*this) /= b; }
mll operator+(ll b) const { return *this + mll(b); }
mll operator-(ll b) const { return *this - mll(b); }
mll operator*(ll b) const { return *this * mll(b); }
friend mll operator+(ll a, const mll &b) { return b + a; }
friend mll operator-(ll a, const mll &b) { return -b + a; }
friend mll operator*(ll a, const mll &b) { return b * a; }
mll &operator+=(const mll &b) {
val = (val + b.val) % MOD;
return *this;
}
mll &operator-=(const mll &b) {
val = (val + MOD - b.val) % MOD;
return *this;
}
mll &operator*=(const mll &b) {
val = (val * b.val) % MOD;
return *this;
}
mll &operator/=(const mll &b) {
ll c = b.val, d = MOD, u = 1, v = 0;
while (d) {
ll t = c / d;
c -= t * d;
swap(c, d);
u -= t * v;
swap(u, v);
}
val = val * u % MOD;
if (val < 0)
val += MOD;
return *this;
}
mll &operator+=(ll b) { return *this += mll(b); }
mll &operator-=(ll b) { return *this -= mll(b); }
mll &operator*=(ll b) { return *this *= mll(b); }
mll &operator/=(ll b) { return *this /= mll(b); }
bool operator==(const mll &b) { return val == b.val; }
bool operator!=(const mll &b) { return val != b.val; }
bool operator==(ll b) { return *this == mll(b); }
bool operator!=(ll b) { return *this != mll(b); }
friend bool operator==(ll a, const mll &b) { return mll(a) == b.val; }
friend bool operator!=(ll a, const mll &b) { return mll(a) != b.val; }
friend ostream &operator<<(ostream &os, const mll &a) { return os << a.val; }
friend istream &operator>>(istream &is, mll &a) { return is >> a.val; }
static mll Combination(ll a, ll b) {
chmin(b, a - b);
if (b < 0)
return mll(0);
mll c = 1;
rep(i, b) c *= a - i;
rep(i, b) c /= i + 1;
return c;
}
};
using vmll = std::vector<mll>;
using vvmll = std::vector<vmll>;
using vvvmll = std::vector<vvmll>;
using vvvvmll = std::vector<vvvmll>;
struct Fast {
Fast() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(std::numeric_limits<double>::max_digits10);
}
} fast; // cin,cout高速化のおまじない+桁数指定
ll mll::MOD = (ll)(1e9 + 7); // 998244353ll;
int main() {
ll N;
cin >> N;
vector<ll> C(N);
rep(i, N) { cin >> C[i]; }
vll prevC(200010, -1);
vmll dp(N, 0);
dp[0] = 1;
rep(i, N) {
if (i > 0) {
dp[i] += dp[i - 1];
if (prevC[C[i]] >= 0 && prevC[C[i]] + 1 < i) {
dp[i] += dp[prevC[C[i]]];
}
}
prevC[C[i]] = i;
}
cout << dp[N - 1] << endl;
return 0;
}
| [
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change",
"expression.operation.binary.change",
"expression.operation.binary.remove"
] | 907,121 | 907,120 | u572472538 | cpp |
p03096 | #include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif
using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
#define reps(i, S, E) for (ll i = (S); i <= (E); i++)
#define rep(i, N) reps(i, 0, N - 1)
#define deps(i, E, S) for (ll i = (E); i >= (S); i--)
#define dep(i, N) deps(i, N - 1, 0)
const ll INF = 1LL << 60;
const int INF_INT = 1 << 30;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
struct mll {
static ll MOD;
ll val;
mll(ll v = 0) : val(v % MOD) {
if (val < 0)
val += MOD;
}
mll operator-() const { return -val; }
mll operator+(const mll &b) const { return val + b.val; }
mll operator-(const mll &b) const { return val - b.val; }
mll operator*(const mll &b) const { return val * b.val; }
mll operator/(const mll &b) const { return mll(*this) /= b; }
mll operator+(ll b) const { return *this + mll(b); }
mll operator-(ll b) const { return *this - mll(b); }
mll operator*(ll b) const { return *this * mll(b); }
friend mll operator+(ll a, const mll &b) { return b + a; }
friend mll operator-(ll a, const mll &b) { return -b + a; }
friend mll operator*(ll a, const mll &b) { return b * a; }
mll &operator+=(const mll &b) {
val = (val + b.val) % MOD;
return *this;
}
mll &operator-=(const mll &b) {
val = (val + MOD - b.val) % MOD;
return *this;
}
mll &operator*=(const mll &b) {
val = (val * b.val) % MOD;
return *this;
}
mll &operator/=(const mll &b) {
ll c = b.val, d = MOD, u = 1, v = 0;
while (d) {
ll t = c / d;
c -= t * d;
swap(c, d);
u -= t * v;
swap(u, v);
}
val = val * u % MOD;
if (val < 0)
val += MOD;
return *this;
}
mll &operator+=(ll b) { return *this += mll(b); }
mll &operator-=(ll b) { return *this -= mll(b); }
mll &operator*=(ll b) { return *this *= mll(b); }
mll &operator/=(ll b) { return *this /= mll(b); }
bool operator==(const mll &b) { return val == b.val; }
bool operator!=(const mll &b) { return val != b.val; }
bool operator==(ll b) { return *this == mll(b); }
bool operator!=(ll b) { return *this != mll(b); }
friend bool operator==(ll a, const mll &b) { return mll(a) == b.val; }
friend bool operator!=(ll a, const mll &b) { return mll(a) != b.val; }
friend ostream &operator<<(ostream &os, const mll &a) { return os << a.val; }
friend istream &operator>>(istream &is, mll &a) { return is >> a.val; }
static mll Combination(ll a, ll b) {
chmin(b, a - b);
if (b < 0)
return mll(0);
mll c = 1;
rep(i, b) c *= a - i;
rep(i, b) c /= i + 1;
return c;
}
};
using vmll = std::vector<mll>;
using vvmll = std::vector<vmll>;
using vvvmll = std::vector<vvmll>;
using vvvvmll = std::vector<vvvmll>;
struct Fast {
Fast() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(std::numeric_limits<double>::max_digits10);
}
} fast; // cin,cout高速化のおまじない+桁数指定
ll mll::MOD = (ll)(1e9 + 7); // 998244353ll;
int main() {
ll N;
cin >> N;
vector<ll> C(N);
rep(i, N) { cin >> C[i]; }
vll prevC(N + 1, -1);
vll dp(N, 0);
dp[0] = 1;
rep(i, N) {
if (i > 0) {
dp[i] += dp[i - 1];
if (prevC[C[i]] >= 0 && prevC[C[i]] + 1 < i) {
dp[i] += dp[prevC[C[i]]];
}
}
prevC[C[i]] = i;
}
cout << dp[N - 1] << endl;
return 0;
}
| #include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif
using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
#define reps(i, S, E) for (ll i = (S); i <= (E); i++)
#define rep(i, N) reps(i, 0, N - 1)
#define deps(i, E, S) for (ll i = (E); i >= (S); i--)
#define dep(i, N) deps(i, N - 1, 0)
const ll INF = 1LL << 60;
const int INF_INT = 1 << 30;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
struct mll {
static ll MOD;
ll val;
mll(ll v = 0) : val(v % MOD) {
if (val < 0)
val += MOD;
}
mll operator-() const { return -val; }
mll operator+(const mll &b) const { return val + b.val; }
mll operator-(const mll &b) const { return val - b.val; }
mll operator*(const mll &b) const { return val * b.val; }
mll operator/(const mll &b) const { return mll(*this) /= b; }
mll operator+(ll b) const { return *this + mll(b); }
mll operator-(ll b) const { return *this - mll(b); }
mll operator*(ll b) const { return *this * mll(b); }
friend mll operator+(ll a, const mll &b) { return b + a; }
friend mll operator-(ll a, const mll &b) { return -b + a; }
friend mll operator*(ll a, const mll &b) { return b * a; }
mll &operator+=(const mll &b) {
val = (val + b.val) % MOD;
return *this;
}
mll &operator-=(const mll &b) {
val = (val + MOD - b.val) % MOD;
return *this;
}
mll &operator*=(const mll &b) {
val = (val * b.val) % MOD;
return *this;
}
mll &operator/=(const mll &b) {
ll c = b.val, d = MOD, u = 1, v = 0;
while (d) {
ll t = c / d;
c -= t * d;
swap(c, d);
u -= t * v;
swap(u, v);
}
val = val * u % MOD;
if (val < 0)
val += MOD;
return *this;
}
mll &operator+=(ll b) { return *this += mll(b); }
mll &operator-=(ll b) { return *this -= mll(b); }
mll &operator*=(ll b) { return *this *= mll(b); }
mll &operator/=(ll b) { return *this /= mll(b); }
bool operator==(const mll &b) { return val == b.val; }
bool operator!=(const mll &b) { return val != b.val; }
bool operator==(ll b) { return *this == mll(b); }
bool operator!=(ll b) { return *this != mll(b); }
friend bool operator==(ll a, const mll &b) { return mll(a) == b.val; }
friend bool operator!=(ll a, const mll &b) { return mll(a) != b.val; }
friend ostream &operator<<(ostream &os, const mll &a) { return os << a.val; }
friend istream &operator>>(istream &is, mll &a) { return is >> a.val; }
static mll Combination(ll a, ll b) {
chmin(b, a - b);
if (b < 0)
return mll(0);
mll c = 1;
rep(i, b) c *= a - i;
rep(i, b) c /= i + 1;
return c;
}
};
using vmll = std::vector<mll>;
using vvmll = std::vector<vmll>;
using vvvmll = std::vector<vvmll>;
using vvvvmll = std::vector<vvvmll>;
struct Fast {
Fast() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(std::numeric_limits<double>::max_digits10);
}
} fast; // cin,cout高速化のおまじない+桁数指定
ll mll::MOD = (ll)(1e9 + 7); // 998244353ll;
int main() {
ll N;
cin >> N;
vector<ll> C(N);
rep(i, N) { cin >> C[i]; }
vll prevC(200010, -1);
vmll dp(N, 0);
dp[0] = 1;
rep(i, N) {
if (i > 0) {
dp[i] += dp[i - 1];
if (prevC[C[i]] >= 0 && prevC[C[i]] + 1 < i) {
dp[i] += dp[prevC[C[i]]];
}
}
prevC[C[i]] = i;
}
cout << dp[N - 1] << endl;
return 0;
}
| [
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change",
"expression.operation.binary.change",
"expression.operation.binary.remove",
"variable_declaration.type.change"
] | 907,122 | 907,120 | u572472538 | cpp |
p03096 | #include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
int main() {
long Nc;
cin >> Nc;
vector<long> C;
for (long i = 0; i < Nc; i++) {
long c;
cin >> c;
c--;
if (i == 0 || c != C[C.size() - 1])
C.push_back(c);
}
long N = C.size();
vector<long> DP(N, 1), L(Nc, 0);
for (long i = 0; i < N; i++) {
if (i != 0)
DP[i] = (DP[i - 1] + L[C[i]]) % MOD;
L[C[i]] = (L[C[i]] + (i > 0 ? DP[i - 1] : 1)) % MOD;
}
cout << DP[N - 1] % MOD;
} | #include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
int main() {
long Nc;
cin >> Nc;
vector<long> C;
for (long i = 0; i < Nc; i++) {
long c;
cin >> c;
c--;
if (i == 0 || c != C[C.size() - 1])
C.push_back(c);
}
long N = C.size();
Nc = 200000;
vector<long> DP(N, 1), L(Nc, 0);
for (long i = 0; i < N; i++) {
if (i != 0)
DP[i] = (DP[i - 1] + L[C[i]]) % MOD;
L[C[i]] = (L[C[i]] + (i > 0 ? DP[i - 1] : 1)) % MOD;
}
cout << DP[N - 1] % MOD;
} | [
"assignment.add"
] | 907,136 | 907,137 | u236193715 | cpp |
p03096 | #include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
int main() {
long Nc;
cin >> Nc;
vector<long> C;
for (long i = 0; i < Nc; i++) {
long c;
cin >> c;
c--;
if (i == 0 || c != C[C.size() - 1])
C.push_back(c);
}
long N = C.size();
vector<long> DP(N, 1), L(Nc, 0);
for (long i = 0; i < N; i++) {
if (i != 0)
DP[i] = (DP[i - 1] + L[C[i]]) % MOD;
L[C[i]] = (L[C[i]] + (i > 0 ? DP[i - 1] : 1)) % MOD;
}
cout << DP[N - 1] % MOD;
} | #include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
int main() {
long Nc;
cin >> Nc;
vector<long> C;
for (long i = 0; i < Nc; i++) {
long c;
cin >> c;
c--;
if (i == 0 || c != C[C.size() - 1])
C.push_back(c);
}
long N = C.size();
Nc = 200000;
vector<long> DP(N, 1), L(Nc, 0);
for (long i = 0; i < N; i++) {
if (i != 0)
DP[i] = (DP[i - 1] + L[C[i]]) % MOD;
L[C[i]] = (L[C[i]] + (i > 0 ? DP[i - 1] : 1)) % MOD;
}
cout << DP[N - 1] % MOD;
} | [
"assignment.add"
] | 907,138 | 907,137 | u236193715 | cpp |
p03096 | #include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define mod 1000000007
#define pb emplace_back
#define mp make_pair
#define fi first
#define sec second
typedef long long ll;
typedef long double ld;
#define pii pair<ll, ll>
#define vi vector<ll>
#define vvi vector<vi>
#define vpi vector<pii>
#define vvpi vector<vpi>
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#define test(t) \
ll t; \
cin >> t; \
while (t--)
#define mem(a, b) memset(a, b, sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(), arr.end()
#define fr(i, n) for (ll i = 0; i < (n); ++i)
#define rep(i, a, b) for (ll i = a; i <= b; ++i)
#define per(i, a, b) for (ll i = a; i >= b; i--)
#define remin(a, b) (a = min((a), (b)))
#define remax(a, b) (a = max((a), (b)))
#ifndef ONLINE_JUDGE
#define debarr(a, n) \
cerr << #a << ":"; \
for (int i = 0; i < n; i++) \
cerr << a[i] << " "; \
cerr << endl;
#define debmat(mat, row, col) \
cerr << #mat << ":\n"; \
for (int i = 0; i < row; i++) { \
for (int j = 0; j < col; j++) \
cerr << mat[i][j] << " "; \
cerr << endl; \
}
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> &p) {
return os << "(" << p.first << "," << p.second << ")";
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &p) {
os << "[";
for (auto &it : p)
os << it << " ";
return os << "]";
}
template <class T> ostream &operator<<(ostream &os, const set<T> &p) {
os << "[";
for (auto &it : p)
os << it << " ";
return os << "]";
}
template <class T> ostream &operator<<(ostream &os, const multiset<T> &p) {
os << "[";
for (auto &it : p)
os << it << " ";
return os << "]";
}
template <class S, class T>
ostream &operator<<(ostream &os, const map<S, T> &p) {
os << "[";
for (auto &it : p)
os << it << " ";
return os << "]";
}
template <class T> void dbs(string str, T t) {
cerr << str << ":" << t << "\n";
}
template <class T, class... S> void dbs(string str, T t, S... s) {
int idx = str.find(',');
cerr << str.substr(0, idx) << ":" << t << ",";
dbs(str.substr(idx + 1), s...);
}
#else
#define pr(...) \
{}
#define debarr(a, n) \
{}
#define debmat(mat, row, col) \
{}
#endif
ll power(ll x, ll y) {
ll res = 1;
while (y) {
if (y & 1)
res = (res * x) % mod;
y = y / 2, x = (x * x) % mod;
}
return res % mod;
}
ll freq[200001];
ll dp[200001];
signed main() {
fast;
ll n;
cin >> n;
ll i;
dp[0] = 1;
for (i = 1; i <= n; i++) {
ll x;
cin >> x;
dp[i] = dp[i - 1];
if (freq[x] and freq[x] != i - 1) {
dp[i] += dp[freq[x] - 1];
}
freq[x] = i;
dp[i] %= mod;
}
cout << dp[n];
}
| #include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define mod 1000000007
#define pb emplace_back
#define mp make_pair
#define fi first
#define sec second
typedef long long ll;
typedef long double ld;
#define pii pair<ll, ll>
#define vi vector<ll>
#define vvi vector<vi>
#define vpi vector<pii>
#define vvpi vector<vpi>
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#define test(t) \
ll t; \
cin >> t; \
while (t--)
#define mem(a, b) memset(a, b, sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(), arr.end()
#define fr(i, n) for (ll i = 0; i < (n); ++i)
#define rep(i, a, b) for (ll i = a; i <= b; ++i)
#define per(i, a, b) for (ll i = a; i >= b; i--)
#define remin(a, b) (a = min((a), (b)))
#define remax(a, b) (a = max((a), (b)))
#ifndef ONLINE_JUDGE
#define debarr(a, n) \
cerr << #a << ":"; \
for (int i = 0; i < n; i++) \
cerr << a[i] << " "; \
cerr << endl;
#define debmat(mat, row, col) \
cerr << #mat << ":\n"; \
for (int i = 0; i < row; i++) { \
for (int j = 0; j < col; j++) \
cerr << mat[i][j] << " "; \
cerr << endl; \
}
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> &p) {
return os << "(" << p.first << "," << p.second << ")";
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &p) {
os << "[";
for (auto &it : p)
os << it << " ";
return os << "]";
}
template <class T> ostream &operator<<(ostream &os, const set<T> &p) {
os << "[";
for (auto &it : p)
os << it << " ";
return os << "]";
}
template <class T> ostream &operator<<(ostream &os, const multiset<T> &p) {
os << "[";
for (auto &it : p)
os << it << " ";
return os << "]";
}
template <class S, class T>
ostream &operator<<(ostream &os, const map<S, T> &p) {
os << "[";
for (auto &it : p)
os << it << " ";
return os << "]";
}
template <class T> void dbs(string str, T t) {
cerr << str << ":" << t << "\n";
}
template <class T, class... S> void dbs(string str, T t, S... s) {
int idx = str.find(',');
cerr << str.substr(0, idx) << ":" << t << ",";
dbs(str.substr(idx + 1), s...);
}
#else
#define pr(...) \
{}
#define debarr(a, n) \
{}
#define debmat(mat, row, col) \
{}
#endif
ll power(ll x, ll y) {
ll res = 1;
while (y) {
if (y & 1)
res = (res * x) % mod;
y = y / 2, x = (x * x) % mod;
}
return res % mod;
}
ll freq[200001];
ll dp[200001];
signed main() {
fast;
ll n;
cin >> n;
ll i;
dp[0] = 1;
for (i = 1; i <= n; i++) {
ll x;
cin >> x;
dp[i] = dp[i - 1];
if (freq[x] and freq[x] != i - 1) {
dp[i] += dp[freq[x]];
}
freq[x] = i;
dp[i] %= mod;
}
cout << dp[n];
}
| [
"expression.operation.binary.remove"
] | 907,141 | 907,142 | u232189905 | cpp |
p03096 | #include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#define INF 1000000009
#define LINF 1000000000000000009
#define double long double
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
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 (a > b) {
a = b;
return 1;
}
return 0;
}
ll gcd(ll n, ll m) { return (m ? gcd(m, n % m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }
ll mod = 1000000007;
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
vector<int> p(n);
vector<ll> dp(n);
dp[0] = 1;
p[a[0]] = 1;
for (int i = 1; i < n; i++) {
dp[i] = dp[i - 1];
if (a[i] != a[i - 1]) {
dp[i] += p[a[i]];
dp[i] %= mod;
p[a[i]] = dp[i];
}
}
cout << dp[n - 1] << endl;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#define INF 1000000009
#define LINF 1000000000000000009
#define double long double
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
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 (a > b) {
a = b;
return 1;
}
return 0;
}
ll gcd(ll n, ll m) { return (m ? gcd(m, n % m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }
ll mod = 1000000007;
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
vector<int> p(300000);
vector<ll> dp(n);
dp[0] = 1;
p[a[0]] = 1;
for (int i = 1; i < n; i++) {
dp[i] = dp[i - 1];
if (a[i] != a[i - 1]) {
dp[i] += p[a[i]];
dp[i] %= mod;
p[a[i]] = dp[i];
}
}
cout << dp[n - 1] << endl;
}
| [] | 907,147 | 907,148 | u179970156 | cpp |
p03096 | #include <bits/stdc++.h>
using namespace std;
const int _ = 2e5 + 7, MOD = 1e9 + 7;
int dp[_], sum[_], arr[_], pos, N;
int main() {
scanf("%d", &N);
int pre = 0;
for (int i = 1, x; i <= N; ++i) {
scanf("%d", &x);
if (pre != x)
arr[++pos] = pre = x;
}
dp[1] = sum[arr[1]] = 1;
for (int i = 2; i <= N; ++i)
sum[arr[i]] = (sum[arr[i]] + (dp[i] = sum[arr[i - 1]])) % MOD;
cout << sum[arr[N]];
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int _ = 2e5 + 7, MOD = 1e9 + 7;
int dp[_], sum[_], arr[_], pos, N;
int main() {
scanf("%d", &N);
int pre = 0;
for (int i = 1, x; i <= N; ++i) {
scanf("%d", &x);
if (pre != x)
arr[++pos] = pre = x;
}
dp[1] = sum[arr[1]] = 1;
for (int i = 2; i <= pos; ++i)
sum[arr[i]] = (sum[arr[i]] + (dp[i] = sum[arr[i - 1]])) % MOD;
cout << sum[arr[pos]];
return 0;
} | [
"identifier.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change",
"variable_access.subscript.index.change",
"io.output.change"
] | 907,166 | 907,167 | u563201135 | cpp |
p03096 | #include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
long long MOD = 1000000007;
int main() {
int N;
cin >> N;
vector<int> C(N, 0);
for (int i = 0; i < N; i++) {
cin >> C[i];
}
vector<long long> pattern(N, 0);
pattern[0] = 1;
vector<int> prev(N + 1, -1);
for (int i = 0; i < N; i++) {
int c = C[i];
if (prev[c] != -1 && prev[c] != i - 1) {
pattern[i] = (pattern[prev[c]] + pattern[i - 1]) % MOD;
} else if (i > 0) {
pattern[i] = pattern[i - 1];
}
prev[c] = i;
}
cout << pattern[N - 1] << endl;
} | #include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
long long MOD = 1000000007;
int main() {
int N;
cin >> N;
vector<int> C(N, 0);
for (int i = 0; i < N; i++) {
cin >> C[i];
}
vector<long long> pattern(N, 0);
pattern[0] = 1;
vector<int> prev(200000 + 1, -1);
for (int i = 0; i < N; i++) {
int c = C[i];
if (prev[c] != -1 && prev[c] != i - 1) {
pattern[i] = (pattern[prev[c]] + pattern[i - 1]) % MOD;
} else if (i > 0) {
pattern[i] = pattern[i - 1];
}
prev[c] = i;
}
cout << pattern[N - 1] << endl;
} | [
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change",
"expression.operation.binary.change"
] | 907,170 | 907,171 | u658993896 | cpp |
p03096 | #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 All(a) (a).begin(), (a).end()
#define sp " "
#define INF 1e18
#define INT_INF 1e9
typedef long long ll;
const ll MOD = 1000000007;
const ll MOD_9 = 998244353;
int N;
int main() {
cin >> N;
vector<int> C(N);
vector<int> F(200010, 0);
long long DP[N + 1];
DP[0] = 1;
Rep(i, N) cin >> C[i + 1];
Rep(i, N) {
if (F[C[i + 1]] == 0)
DP[i + 1] = DP[i];
else if (F[C[i + 1]] == i)
DP[i + 1] = DP[i];
else
DP[i + 1] = DP[i] + DP[F[C[i + 1]]];
F[C[i + 1]] = i + 1;
DP[i + 1] %= MOD;
// cout << DP[i+1] << endl;
}
cout << DP[N] << endl;
// cin >> N;
} | #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 All(a) (a).begin(), (a).end()
#define sp " "
#define INF 1e18
#define INT_INF 1e9
typedef long long ll;
const ll MOD = 1000000007;
const ll MOD_9 = 998244353;
int N;
int main() {
cin >> N;
vector<int> C(N + 1);
vector<int> F(200010, 0);
long long DP[N + 1];
DP[0] = 1;
Rep(i, N) cin >> C[i + 1];
Rep(i, N) {
if (F[C[i + 1]] == 0)
DP[i + 1] = DP[i];
else if (F[C[i + 1]] == i)
DP[i + 1] = DP[i];
else
DP[i + 1] = DP[i] + DP[F[C[i + 1]]];
F[C[i + 1]] = i + 1;
DP[i + 1] %= MOD;
// cout << DP[i+1] << endl;
}
cout << DP[N] << endl;
// cin >> N;
} | [
"assignment.change"
] | 907,182 | 907,183 | u280114218 | cpp |
p03096 | #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 All(a) (a).begin(), (a).end()
#define sp " "
#define INF 1e18
#define INT_INF 1e9
typedef long long ll;
const ll MOD = 1000000007;
const ll MOD_9 = 998244353;
int N;
int main() {
cin >> N;
vector<int> C(N + 1);
vector<int> F(N + 1, 0);
long long DP[N + 1];
DP[0] = 1;
Rep(i, N) cin >> C[i + 1];
Rep(i, N) {
if (F[C[i + 1]] == 0)
DP[i + 1] = DP[i];
else if (F[C[i + 1]] == i)
DP[i + 1] = DP[i];
else
DP[i + 1] = DP[i] + DP[F[C[i + 1]]];
F[C[i + 1]] = i + 1;
DP[i + 1] %= MOD;
// cout << DP[i+1] << endl;
}
cout << DP[N] << endl;
// cin >> N;
} | #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 All(a) (a).begin(), (a).end()
#define sp " "
#define INF 1e18
#define INT_INF 1e9
typedef long long ll;
const ll MOD = 1000000007;
const ll MOD_9 = 998244353;
int N;
int main() {
cin >> N;
vector<int> C(N + 1);
vector<int> F(200010, 0);
long long DP[N + 1];
DP[0] = 1;
Rep(i, N) cin >> C[i + 1];
Rep(i, N) {
if (F[C[i + 1]] == 0)
DP[i + 1] = DP[i];
else if (F[C[i + 1]] == i)
DP[i + 1] = DP[i];
else
DP[i + 1] = DP[i] + DP[F[C[i + 1]]];
F[C[i + 1]] = i + 1;
DP[i + 1] %= MOD;
// cout << DP[i+1] << endl;
}
cout << DP[N] << endl;
// cin >> N;
} | [
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change",
"expression.operation.binary.change",
"expression.operation.binary.remove"
] | 907,185 | 907,183 | u280114218 | cpp |
p03096 | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;
const int MOD = 1000000007;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll N;
cin >> N;
vector<ll> C(N);
Rep(i, N) { cin >> C[i]; }
vec pre(N + 1, -1);
vec check(N, -1);
Rep(i, N) {
check[i] = pre[C[i]];
pre[C[i]] = i;
}
// Rep (i, N) {
// cout << check[i] << " ";
// }
// cout << "\n";
vec dp(N + 1);
dp[0] = 1;
Rep(i, N) {
dp[i + 1] = dp[i];
ll j = check[i];
if (j == i - 1) {
continue;
}
if (j != -1) {
dp[i + 1] += dp[j + 1];
dp[i + 1] %= MOD;
}
}
cout << dp[N] << "\n";
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;
const int MOD = 1000000007;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll N;
cin >> N;
vector<ll> C(N);
Rep(i, N) { cin >> C[i]; }
vec pre(2e5 + 1, -1);
vec check(N, -1);
Rep(i, N) {
check[i] = pre[C[i]];
pre[C[i]] = i;
}
// Rep (i, N) {
// cout << check[i] << " ";
// }
// cout << "\n";
vec dp(N + 1);
dp[0] = 1;
Rep(i, N) {
dp[i + 1] = dp[i];
ll j = check[i];
if (j == i - 1) {
continue;
}
if (j != -1) {
dp[i + 1] += dp[j + 1];
dp[i + 1] %= MOD;
}
}
cout << dp[N] << "\n";
} | [
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change",
"expression.operation.binary.change"
] | 907,186 | 907,187 | u017271745 | cpp |
p03096 | #include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1},
Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
int n;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n;
vector<ll> count(n + 1, 0);
ll dp[n + 1];
dp[0] = 1;
int before = -1;
for (int i = 1; i <= n; i++) {
int temp;
cin >> temp;
dp[i] = dp[i - 1];
if (before == temp)
continue;
before = temp;
// if(count[temp].size()!=0){
/*
for(auto iter=count[temp].begin();iter!=count[temp].end();iter++){
if(i-*iter>1){
dp[i]+=dp[*iter-1];
dp[i]%=MOD;
}
}
*/
dp[i] += count[temp];
dp[i] %= MOD;
//}
count[temp] += dp[i - 1];
count[temp] %= MOD;
}
cout << dp[n] << "\n";
}
| #include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1},
Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
int n;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n;
vector<ll> count(2 * 100000, 0);
ll dp[n + 1];
dp[0] = 1;
int before = -1;
for (int i = 1; i <= n; i++) {
int temp;
cin >> temp;
dp[i] = dp[i - 1];
if (before == temp)
continue;
before = temp;
// if(count[temp].size()!=0){
/*
for(auto iter=count[temp].begin();iter!=count[temp].end();iter++){
if(i-*iter>1){
dp[i]+=dp[*iter-1];
dp[i]%=MOD;
}
}
*/
dp[i] += count[temp];
dp[i] %= MOD;
//}
count[temp] += dp[i - 1];
count[temp] %= MOD;
}
cout << dp[n] << "\n";
}
| [] | 907,194 | 907,195 | u155416173 | cpp |
p03096 | #include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1},
Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
int n;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n;
vector<ll> count(n + 1, 0);
ll dp[n + 1];
dp[0] = 1;
int before;
for (int i = 1; i <= n; i++) {
int temp;
cin >> temp;
dp[i] = dp[i - 1];
if (before == temp)
continue;
before = temp;
// if(count[temp].size()!=0){
/*
for(auto iter=count[temp].begin();iter!=count[temp].end();iter++){
if(i-*iter>1){
dp[i]+=dp[*iter-1];
dp[i]%=MOD;
}
}
*/
dp[i] += count[temp];
dp[i] %= MOD;
//}
count[temp] += dp[i - 1];
count[temp] %= MOD;
}
cout << dp[n] << "\n";
}
| #include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1},
Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
int n;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n;
vector<ll> count(2 * 100000, 0);
ll dp[n + 1];
dp[0] = 1;
int before = -1;
for (int i = 1; i <= n; i++) {
int temp;
cin >> temp;
dp[i] = dp[i - 1];
if (before == temp)
continue;
before = temp;
// if(count[temp].size()!=0){
/*
for(auto iter=count[temp].begin();iter!=count[temp].end();iter++){
if(i-*iter>1){
dp[i]+=dp[*iter-1];
dp[i]%=MOD;
}
}
*/
dp[i] += count[temp];
dp[i] %= MOD;
//}
count[temp] += dp[i - 1];
count[temp] %= MOD;
}
cout << dp[n] << "\n";
}
| [
"variable_declaration.value.change"
] | 907,196 | 907,195 | u155416173 | cpp |
p03096 | #include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD 1000000007
int main() {
int n;
cin >> n;
vector<int> clr(n);
rep(i, n) cin >> clr.at(i);
vector<long> dp(n + 1, 0);
vector<long> hs(n + 1, 0);
dp.at(0) = 1;
hs.at(clr.at(0)) = 1;
for (int i = 1; i <= n; i++) {
int c = clr.at(i - 1);
if (i != n) {
if (clr.at(i - 1) == clr.at(i))
continue;
}
dp.at(i) = hs.at(c) % MOD;
if (i == n)
continue;
hs.at(clr.at(i)) += dp.at(i);
hs.at(clr.at(i)) %= MOD;
}
cout << dp.at(n) % MOD << endl;
} | #include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD 1000000007
int main() {
int n;
cin >> n;
vector<int> clr(n);
rep(i, n) cin >> clr.at(i);
vector<long> dp(n + 1, 0);
vector<long> hs(200001, 0);
dp.at(0) = 1;
hs.at(clr.at(0)) = 1;
for (int i = 1; i <= n; i++) {
int c = clr.at(i - 1);
if (i != n) {
if (clr.at(i - 1) == clr.at(i))
continue;
}
dp.at(i) = hs.at(c) % MOD;
if (i == n)
continue;
hs.at(clr.at(i)) += dp.at(i);
hs.at(clr.at(i)) %= MOD;
}
cout << dp.at(n) % MOD << endl;
} | [
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change",
"expression.operation.binary.change",
"expression.operation.binary.remove"
] | 907,199 | 907,200 | u184335045 | cpp |
p03096 | #define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#define BIT(nr) (1UL << (nr))
#define int long long
//#define ll long long
#define double long double
#define mod 1000000007
#define MAXN (int)1e+5 * 2 + 1
#define LL_MAX 9223372036854775807 //ない環境用
#define LL_HALFMAX 9223372036854775807 / 2 //ない環境用
#define MIN -(9223372036854775807 / 2)
#define REP(i, a, n) for (int i = (a); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define FOR(it, c) \
for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define mp make_pair
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
if (a > b)
a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
if (a < b)
a = b;
}
using namespace std;
std::mt19937 mt((int)time(0));
int dx[4] = {0, 1, 0, -1}; // x軸方向への変位
int dy[4] = {1, 0, -1, 0}; // y軸方向への変位
using Weight = int;
using Flow = int;
struct Edge {
int src, dst;
Weight weight;
Flow cap;
Edge() : src(0), dst(0), weight(0) {}
Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};
using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;
void add_edge(Graph &g, int a, int b, Weight w = 1) {
g[a].emplace_back(a, b, w);
g[b].emplace_back(b, a, w);
}
void add_arc(Graph &g, int a, int b, Weight w = 1) {
g[a].emplace_back(a, b, w);
}
struct uf_tree {
std::vector<int> parent;
int __size;
uf_tree(int size_) : parent(size_, -1), __size(size_) {}
void unite(int x, int y) {
if ((x = find(x)) != (y = find(y))) {
if (parent[y] < parent[x])
std::swap(x, y);
parent[x] += parent[y];
parent[y] = x;
__size--;
}
}
bool is_same(int x, int y) { return find(x) == find(y); }
int find(int x) { return parent[x] < 0 ? x : parent[x] = find(parent[x]); }
int size(int x) { return -parent[find(x)]; }
int size() { return __size; }
};
//!!!問題をちゃんと読む!!!
//!!!問題をちゃんと読め!!!
//!!!問題は読みましたか?!!!
template <signed M, unsigned T> struct mod_int {
constexpr static signed MODULO = M;
constexpr static unsigned TABLE_SIZE = T;
signed x;
mod_int() : x(0) {}
mod_int(long long y)
: x(static_cast<signed>(y >= 0 ? y % MODULO : MODULO - (-y) % MODULO)) {}
mod_int(signed y) : x(y >= 0 ? y % MODULO : MODULO - (-y) % MODULO) {}
mod_int &operator+=(const mod_int &rhs) {
if ((x += rhs.x) >= MODULO)
x -= MODULO;
return *this;
}
mod_int &operator-=(const mod_int &rhs) {
if ((x += MODULO - rhs.x) >= MODULO)
x -= MODULO;
return *this;
}
mod_int &operator*=(const mod_int &rhs) {
x = static_cast<signed>(1LL * x * rhs.x % MODULO);
return *this;
}
mod_int &operator/=(const mod_int &rhs) {
x = static_cast<signed>((1LL * x * rhs.inv().x) % MODULO);
return *this;
}
mod_int operator-() const { return mod_int(-x); }
mod_int operator+(const mod_int &rhs) const { return mod_int(*this) += rhs; }
mod_int operator-(const mod_int &rhs) const { return mod_int(*this) -= rhs; }
mod_int operator*(const mod_int &rhs) const { return mod_int(*this) *= rhs; }
mod_int operator/(const mod_int &rhs) const { return mod_int(*this) /= rhs; }
bool operator<(const mod_int &rhs) const { return x < rhs.x; }
mod_int inv() const {
assert(x != 0);
if (x <= static_cast<signed>(TABLE_SIZE)) {
if (_inv[1].x == 0)
prepare();
return _inv[x];
} else {
signed a = x, b = MODULO, u = 1, v = 0, t;
while (b) {
t = a / b;
a -= t * b;
std::swap(a, b);
u -= t * v;
std::swap(u, v);
}
return mod_int(u);
}
}
mod_int pow(long long t) const {
assert(!(x == 0 && t == 0));
mod_int e = *this, res = mod_int(1);
for (; t; e *= e, t >>= 1)
if (t & 1)
res *= e;
return res;
}
mod_int fact() {
if (_fact[0].x == 0)
prepare();
return _fact[x];
}
mod_int inv_fact() {
if (_fact[0].x == 0)
prepare();
return _inv_fact[x];
}
mod_int choose(mod_int y) {
assert(y.x <= x);
return this->fact() * y.inv_fact() * mod_int(x - y.x).inv_fact();
}
static mod_int _inv[TABLE_SIZE + 1];
static mod_int _fact[TABLE_SIZE + 1];
static mod_int _inv_fact[TABLE_SIZE + 1];
static void prepare() {
_inv[1] = 1;
for (int i = 2; i <= (int)TABLE_SIZE; ++i) {
_inv[i] = 1LL * _inv[MODULO % i].x * (MODULO - MODULO / i) % MODULO;
}
_fact[0] = 1;
for (unsigned i = 1; i <= TABLE_SIZE; ++i) {
_fact[i] = _fact[i - 1] * signed(i);
}
_inv_fact[TABLE_SIZE] = _fact[TABLE_SIZE].inv();
for (int i = (int)TABLE_SIZE - 1; i >= 0; --i) {
_inv_fact[i] = _inv_fact[i + 1] * (i + 1);
}
}
};
template <signed M, unsigned F>
std::ostream &operator<<(std::ostream &os, const mod_int<M, F> &rhs) {
return os << rhs.x;
}
template <signed M, unsigned F>
std::istream &operator>>(std::istream &is, mod_int<M, F> &rhs) {
long long s;
is >> s;
rhs = mod_int<M, F>(s);
return is;
}
template <signed M, unsigned F>
mod_int<M, F> mod_int<M, F>::_inv[TABLE_SIZE + 1];
template <signed M, unsigned F>
mod_int<M, F> mod_int<M, F>::_fact[TABLE_SIZE + 1];
template <signed M, unsigned F>
mod_int<M, F> mod_int<M, F>::_inv_fact[TABLE_SIZE + 1];
template <signed M, unsigned F>
bool operator==(const mod_int<M, F> &lhs, const mod_int<M, F> &rhs) {
return lhs.x == rhs.x;
}
template <int M, unsigned F>
bool operator!=(const mod_int<M, F> &lhs, const mod_int<M, F> &rhs) {
return !(lhs == rhs);
}
const signed MF = 1000010;
const signed MOD = 1000000007;
using mint = mod_int<MOD, MF>;
mint binom(int n, int r) {
return (r < 0 || r > n || n < 0) ? 0 : mint(n).choose(r);
}
mint fact(int n) { return mint(n).fact(); }
mint inv_fact(int n) { return mint(n).inv_fact(); }
//出典 http://beet-aizu.hatenablog.com/entry/2017/12/01/225955
/*
コンストラクタ引数説明
int n_
要素数。
f
2つの要素Tをマージするための関数。
区間MAX区間更新の時: max
区間Sum区間Addの時: +
g
1つの要素Tに作用素Eを適用するための関数。
区間MAX区間更新の時: =
区間Sum区間Addの時: +
h
2つの作用素Eをマージするための関数。
区間MAX区間更新の時: =
区間Sum区間Addの時: +
T d1
演算fの単位元。
区間MAX区間更新の時: -INF
区間Sum区間Addの時: 0
E d0,
g, hの単位元。
区間MAX区間更新の時: 定義域外のどこか
区間Sum区間Addの時: 0
vector<T> v = vector<T>()
セグ木を構成するときのvector
P p = [](E a, int b) {return a; }
区間の長さbを引数に取り、区間の長さによって変化する作用素E'を返す関数。
例えば、区間MAX区間Addの時なんかは区間長によって足すべき数が変化するので必要
区間Sum区間Addの時: *
//具体例
//区間chmin, 区間min
auto myMin = [](int a, int b) {return min(a, b); };
SegmentTree<int, int> seg(n, myMin, myMin, myMin, LL_HALFMAX, LL_HALFMAX);
//区間update、区間min
SegmentTree<int, int> seg(n, myMin, myMin, myMin, LL_HALFMAX, LL_HALFMAX);
*/
template <typename T, typename E> struct SegmentTree {
typedef function<T(T, T)> F;
typedef function<T(T, E)> G;
typedef function<E(E, E)> H;
typedef function<E(E, int)> P;
int n;
F f;
G g;
H h;
P p;
T d1;
E d0;
vector<T> dat;
vector<E> laz;
SegmentTree(
int n_, F f, G g, H h, T d1, E d0, vector<T> v = vector<T>(),
P p = [](E a, int b) { return a; })
: f(f), g(g), h(h), d1(d1), d0(d0), p(p) {
init(n_);
if (n_ == (int)v.size())
build(n_, v);
}
//初期化。要素配列と遅延配列を2*n-1個にする
void init(int n_) {
n = 1;
while (n < n_)
n *= 2;
dat.clear();
dat.resize(2 * n - 1, d1);
laz.clear();
laz.resize(2 * n - 1, d0);
}
//既存のvectorからセグ木を構築
void build(int n_, vector<T> v) {
for (int i = 0; i < n_; i++)
dat[i + n - 1] = v[i];
for (int i = n - 2; i >= 0; i--)
dat[i] = f(dat[i * 2 + 1], dat[i * 2 + 2]);
}
//ノードを評価する。
inline void eval(int len, int k) {
//遅延配列に単位元が入ってたら評価済みなのでおしまい
if (laz[k] == d0)
return;
//葉ノードでないなら遅延伝播する
if (k * 2 + 1 < n * 2 - 1) {
// h: 2つの作用素を引数に取り合成した作用素を返す関数
laz[k * 2 + 1] = h(laz[k * 2 + 1], laz[k]);
laz[k * 2 + 2] = h(laz[k * 2 + 2], laz[k]);
}
// p:
// このノードに対応する区間長と作用素を引数に取り、区間長に対応する作用素を返す関数
// dat[k] にlaz に溜めていた作用素を適用(g:
// 要素型と作用素型を引数に取り、要素に作用素を作用させた結果を返す関数、ここでの作用素とは区間Sum区間Addなら
// (+ 3) とか)
dat[k] = g(dat[k], p(laz[k], len));
//適用し終わったので遅延配列をクリア
laz[k] = d0;
}
//[l,r)の区間を再帰的に見ながら0-indexedの[a, b)を更新する
T update(int a, int b, E x, int k, int l, int r) {
//先に評価
eval(r - l, k);
//範囲外ならなにもしないでそのノードが持つ値を返す
if (r <= a || b <= l)
return dat[k];
//完全被覆なら既に遅延配列に入っている作用素と追加したい作用素をマージした後にそれを要素に作用させた結果を返す、pは区間長に対応する作用素を得るための(ry
if (a <= l && r <= b) {
laz[k] = h(laz[k], x);
return g(dat[k], p(laz[k], r - l));
}
//完全被覆でも範囲外でもないなら(中途半端にかぶっているなら)完全被覆と範囲外の境界が見えるまで木を潜って変化後の値を得る
return dat[k] = f(update(a, b, x, k * 2 + 1, l, (l + r) / 2),
update(a, b, x, k * 2 + 2, (l + r) / 2, r));
}
T update(int a, int b, E x) { return update(a, b, x, 0, 0, n); }
T query(int a, int b, int k, int l, int r) {
eval(r - l, k);
//範囲外なら単位元を返す
if (r <= a || b <= l)
return d1;
//完全被覆ならそのまま返す
if (a <= l && r <= b)
return dat[k];
//一部被覆なら完全被覆と範囲外に分かれるまで木を潜る
T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return f(vl, vr);
}
// 0-indexedで[a, b)の区間*を求める
T query(int a, int b) { return query(a, b, 0, 0, n); }
};
//座標圧縮
class compress {
public:
static const int MAP = 10000000;
map<int, int> zip;
int unzip[MAP];
compress(vector<int> &x) {
sort(x.begin(), x.end());
x.erase(unique(x.begin(), x.end()), x.end());
for (int i = 0; i < x.size(); i++) {
zip[x[i]] = i;
unzip[i] = x[i];
}
}
};
unsigned euclidean_gcd(unsigned a, unsigned b) {
while (1) {
if (a < b)
swap(a, b);
if (!b)
break;
a %= b;
}
return a;
}
// https://ei1333.github.io/luzhiled/snippets/dp/cumulative-sum-2d.html
template <class T> struct CumulativeSum2D {
vector<vector<T>> data;
CumulativeSum2D(int W, int H) : data(W + 1, vector<int>(H + 1, 0)) {}
void add(int x, int y, T z) {
++x, ++y;
if (x >= data.size() || y >= data[0].size())
return;
data[x][y] += z;
}
void build() {
for (int i = 1; i < data.size(); i++) {
for (int j = 1; j < data[i].size(); j++) {
data[i][j] += data[i][j - 1] + data[i - 1][j] - data[i - 1][j - 1];
}
}
}
T query(int sx, int sy, int gx, int gy) {
return (data[gx][gy] - data[sx][gy] - data[gx][sy] + data[sx][sy]);
}
};
// lib
int nC2(int n) { return n * (n - 1) / 2; }
class node {
public:
int depth;
int num;
node(int d, int n) {
depth = d;
num = n;
}
};
CumulativeSum2D<int> sumB(4001, 4001);
template <class T> struct CumulativeSum {
vector<T> data;
CumulativeSum(int sz) : data(sz, 0){};
void add(int k, T x) { data[k] += x; }
void build() {
for (int i = 1; i < data.size(); i++) {
data[i] += data[i - 1];
}
}
T query(int k) {
if (k < 0)
return (0);
return (data[min(k, (int)data.size() - 1)]);
}
//[left, right]の和
T query(int left, int right) { return query(right) - query(left - 1); }
};
std::vector<bool> IsPrime;
void sieve(size_t max) {
if (max + 1 > IsPrime.size()) { // resizeで要素数が減らないように
IsPrime.resize(max + 1, true); // IsPrimeに必要な要素数を確保
}
IsPrime[0] = false; // 0は素数ではない
IsPrime[1] = false; // 1は素数ではない
for (size_t i = 2; i * i <= max; ++i) // 0からsqrt(max)まで調べる
if (IsPrime[i]) // iが素数ならば
for (size_t j = 2; i * j <= max; ++j) // (max以下の)iの倍数は
IsPrime[i * j] = false; // 素数ではない
}
vector<int64_t> divisor(int64_t n) {
vector<int64_t> ret;
for (int64_t i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n)
ret.push_back(n / i);
}
}
sort(begin(ret), end(ret));
return (ret);
}
// 汎用的な二分探索のテンプレ(めぐる式)
int binary_search(function<bool(int)> isOk, int ng, int ok) {
/* ok と ng のどちらが大きいかわからないことを考慮 */
while (abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isOk(mid))
ok = mid;
else
ng = mid;
}
return ok;
}
std::pair<std::vector<Weight>, bool> bellmanFord(const Graph &g, int s) {
int n = g.size();
const Weight inf = std::numeric_limits<Weight>::max() / 8;
Edges es;
for (int i = 0; i < n; i++)
for (auto &e : g[i])
es.emplace_back(e);
//初期化、スタート地点以外の距離は無限大
std::vector<Weight> dist(n, inf);
dist[s] = 0;
bool negCycle = false;
for (int i = 0;; i++) {
bool update = false;
//すべての辺について、その辺をとおった場合に最短経路が更新できる場合は更新する
for (auto &e : es) {
if (dist[e.src] != inf && dist[e.dst] > dist[e.src] + e.weight) {
dist[e.dst] = dist[e.src] + e.weight;
update = true;
}
}
//更新がなくなったらおはり
if (!update)
break;
// n回以上更新されてたら負閉路がある
if (i > n) {
negCycle = true;
break;
}
}
return std::make_pair(dist, !negCycle);
}
//ゴールを指定して、それまでのパスに負閉路がなかったらOK(これは嘘)
std::pair<std::vector<Weight>, bool> bellmanFord(const Graph &g, int s, int d) {
int n = g.size();
const Weight inf = std::numeric_limits<Weight>::max() / 8;
Edges es;
for (int i = 0; i < n; i++)
for (auto &e : g[i])
es.emplace_back(e);
//初期化、スタート地点以外の距離は無限大
std::vector<Weight> dist(n, inf);
dist[s] = 0;
bool negCycle = false;
for (int i = 0; i < n * 2; i++) {
bool update = false;
//すべての辺について、その辺をとおった場合に最短経路が更新できる場合は更新する
for (auto &e : es) {
if (dist[e.src] != inf && dist[e.dst] > dist[e.src] + e.weight) {
dist[e.dst] = dist[e.src] + e.weight;
update = true;
if (e.dst == d && i == n * 2 - 1)
negCycle = true;
}
}
//更新がなくなったらおはり
if (!update)
break;
}
return std::make_pair(dist, !negCycle);
}
// R[i] == S[i] を中心とした極大回文長 なるvector Rを返す
vector<int> Manachar(string S) {
int len = S.length();
vector<int> R(len);
int i = 0, j = 0;
while (i < S.size()) {
while (i - j >= 0 && i + j < S.size() && S[i - j] == S[i + j])
++j;
R[i] = j;
int k = 1;
while (i - k >= 0 && i + k < S.size() && k + R[i - k] < j)
R[i + k] = R[i - k], ++k;
i += k;
j -= k;
}
return R;
}
std::vector<int> tsort(const Graph &g) {
int n = g.size(), k = 0;
std::vector<int> ord(n), in(n);
for (auto &es : g)
for (auto &e : es)
in[e.dst]++;
std::queue<int> q;
//入次数0の点をキューに追加
for (int i = 0; i < n; ++i)
if (in[i] == 0)
q.push(i);
while (q.size()) {
int v = q.front();
// Sから node n を削除する
q.pop();
// L に n を追加する
ord[k++] = v;
for (auto &e : g[v]) {
//選択した点から出てる辺を削除、0になったらキューに追加
if (--in[e.dst] == 0) {
q.push(e.dst);
}
}
}
return *std::max_element(in.begin(), in.end()) == 0 ? ord
: std::vector<int>();
}
std::vector<Weight> dijkstra(const Graph &g, int s) {
const Weight INF = std::numeric_limits<Weight>::max() / 8;
using state = std::tuple<Weight, int>;
std::priority_queue<state> q;
std::vector<Weight> dist(g.size(), INF);
dist[s] = 0;
q.emplace(0, s);
while (q.size()) {
Weight d;
int v;
std::tie(d, v) = q.top();
q.pop();
d *= -1;
/* if(v == t) return d; */
if (dist[v] < d)
continue;
for (auto &e : g[v]) {
if (dist[e.dst] > dist[v] + e.weight) {
dist[e.dst] = dist[v] + e.weight;
q.emplace(-dist[e.dst], e.dst);
}
}
}
return dist;
}
Matrix WarshallFloyd(const Graph &g) {
auto const INF = std::numeric_limits<Weight>::max() / 8;
int n = g.size();
Matrix d(n, Array(n, INF));
rep(i, n) d[i][i] = 0;
rep(i, n) for (auto &e : g[i]) d[e.src][e.dst] =
std::min(d[e.src][e.dst], e.weight);
rep(k, n) rep(i, n) rep(j, n) {
if (d[i][k] != INF && d[k][j] != INF) {
d[i][j] = std::min(d[i][j], d[i][k] + d[k][j]);
}
}
return d;
}
const int BLACK = 1, WHITE = 0;
bool isValid(vector<vector<int>> &mapData, int gyo, int retu) {
bool f = true;
rep(i, gyo) {
rep(j, retu) {
int colorCnt = 0;
if (j > 0 && mapData[i][j] == mapData[i][j - 1]) {
colorCnt++;
}
if (i > 0 && mapData[i][j] == mapData[i - 1][j]) {
colorCnt++;
}
if (i < gyo - 1 && mapData[i][j] == mapData[i + 1][j]) {
colorCnt++;
}
if (j < retu - 1 && mapData[i][j] == mapData[i][j + 1]) {
colorCnt++;
}
if (colorCnt > 1) {
f = false;
}
}
}
return f;
}
void getNext(int nowX, int nowY, int *pOutX, int *pOutY, int gyo, int retu) {
if (nowX == retu - 1) {
*pOutY = nowY + 1;
*pOutX = 0;
return;
}
*pOutX = nowX + 1;
*pOutY = nowY;
}
void dfs(vector<vector<int>> mapData, int nowX, int nowY, int gyo, int retu,
int *outCnt) {
//最後まできてたら
if (nowX == retu - 1 && nowY == gyo - 1) {
mapData[nowY][nowX] = BLACK;
if (isValid(mapData, gyo, retu)) {
*outCnt = *outCnt + 1;
}
mapData[nowY][nowX] = WHITE;
if (isValid(mapData, gyo, retu)) {
*outCnt = *outCnt + 1;
}
return;
}
mapData[nowY][nowX] = BLACK;
int nextX, nextY;
getNext(nowX, nowY, &nextX, &nextY, gyo, retu);
dfs(mapData, nextX, nextY, gyo, retu, outCnt);
mapData[nowY][nowX] = WHITE;
getNext(nowX, nowY, &nextX, &nextY, gyo, retu);
dfs(mapData, nextX, nextY, gyo, retu, outCnt);
}
void dec(map<int, int> &ma, int a) {
ma[a]--;
if (ma[a] == 0) {
ma.erase(a);
}
}
int solve(bool idZeroPositive, int n, vector<int> a) {
int ans = 0;
if (idZeroPositive) {
if (a[0] <= 0) {
ans += -a[0] + 1;
a[0] = 1;
}
} else {
if (a[0] >= 0) {
ans += a[0] + 1;
a[0] = -1;
}
}
int su = 0;
rep(i, n) {
su += a[i];
if (idZeroPositive) {
if (i % 2 == 0 && su <= 0) {
ans += -su + 1;
su = 1;
}
if (i % 2 == 1 && su >= 0) {
ans += su + 1;
su = -1;
}
} else {
if (i % 2 == 1 && su <= 0) {
ans += -su + 1;
su = 1;
}
if (i % 2 == 0 && su >= 0) {
ans += su + 1;
su = -1;
}
}
}
return ans;
}
mint dp[210000];
signed main() {
int N;
cin >> N;
vector<int> C(N);
rep(i, N) { cin >> C[i]; }
vector<int> places[210000];
rep(i, 210000) { places[i].clear(); }
rep(i, N) { places[C[i]].push_back(i); }
dp[0] = 1;
REPS(i, N) {
//操作をしない、直前の分割方法の場合の数をそのまま足す
dp[i] += dp[i - 1];
int color = C[i - 1];
//今見ている色がcolor 色の何番目の要素かを求める
auto it = lower_bound(places[color].begin(), places[color].end(), i - 1);
int ind = it - places[color].begin();
if (ind > 0) {
//直近の相方
int pairInd = places[color][ind - 1];
if (i - 1 - pairInd > 1) {
dp[i] += dp[pairInd];
}
}
}
cout << dp[N] << "\n";
}
| #define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#define BIT(nr) (1UL << (nr))
#define int long long
//#define ll long long
#define double long double
#define mod 1000000007
#define MAXN (int)1e+5 * 2 + 1
#define LL_MAX 9223372036854775807 //ない環境用
#define LL_HALFMAX 9223372036854775807 / 2 //ない環境用
#define MIN -(9223372036854775807 / 2)
#define REP(i, a, n) for (int i = (a); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define FOR(it, c) \
for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define mp make_pair
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
if (a > b)
a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
if (a < b)
a = b;
}
using namespace std;
std::mt19937 mt((int)time(0));
int dx[4] = {0, 1, 0, -1}; // x軸方向への変位
int dy[4] = {1, 0, -1, 0}; // y軸方向への変位
using Weight = int;
using Flow = int;
struct Edge {
int src, dst;
Weight weight;
Flow cap;
Edge() : src(0), dst(0), weight(0) {}
Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};
using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;
void add_edge(Graph &g, int a, int b, Weight w = 1) {
g[a].emplace_back(a, b, w);
g[b].emplace_back(b, a, w);
}
void add_arc(Graph &g, int a, int b, Weight w = 1) {
g[a].emplace_back(a, b, w);
}
struct uf_tree {
std::vector<int> parent;
int __size;
uf_tree(int size_) : parent(size_, -1), __size(size_) {}
void unite(int x, int y) {
if ((x = find(x)) != (y = find(y))) {
if (parent[y] < parent[x])
std::swap(x, y);
parent[x] += parent[y];
parent[y] = x;
__size--;
}
}
bool is_same(int x, int y) { return find(x) == find(y); }
int find(int x) { return parent[x] < 0 ? x : parent[x] = find(parent[x]); }
int size(int x) { return -parent[find(x)]; }
int size() { return __size; }
};
//!!!問題をちゃんと読む!!!
//!!!問題をちゃんと読め!!!
//!!!問題は読みましたか?!!!
template <signed M, unsigned T> struct mod_int {
constexpr static signed MODULO = M;
constexpr static unsigned TABLE_SIZE = T;
signed x;
mod_int() : x(0) {}
mod_int(long long y)
: x(static_cast<signed>(y >= 0 ? y % MODULO : MODULO - (-y) % MODULO)) {}
mod_int(signed y) : x(y >= 0 ? y % MODULO : MODULO - (-y) % MODULO) {}
mod_int &operator+=(const mod_int &rhs) {
if ((x += rhs.x) >= MODULO)
x -= MODULO;
return *this;
}
mod_int &operator-=(const mod_int &rhs) {
if ((x += MODULO - rhs.x) >= MODULO)
x -= MODULO;
return *this;
}
mod_int &operator*=(const mod_int &rhs) {
x = static_cast<signed>(1LL * x * rhs.x % MODULO);
return *this;
}
mod_int &operator/=(const mod_int &rhs) {
x = static_cast<signed>((1LL * x * rhs.inv().x) % MODULO);
return *this;
}
mod_int operator-() const { return mod_int(-x); }
mod_int operator+(const mod_int &rhs) const { return mod_int(*this) += rhs; }
mod_int operator-(const mod_int &rhs) const { return mod_int(*this) -= rhs; }
mod_int operator*(const mod_int &rhs) const { return mod_int(*this) *= rhs; }
mod_int operator/(const mod_int &rhs) const { return mod_int(*this) /= rhs; }
bool operator<(const mod_int &rhs) const { return x < rhs.x; }
mod_int inv() const {
assert(x != 0);
if (x <= static_cast<signed>(TABLE_SIZE)) {
if (_inv[1].x == 0)
prepare();
return _inv[x];
} else {
signed a = x, b = MODULO, u = 1, v = 0, t;
while (b) {
t = a / b;
a -= t * b;
std::swap(a, b);
u -= t * v;
std::swap(u, v);
}
return mod_int(u);
}
}
mod_int pow(long long t) const {
assert(!(x == 0 && t == 0));
mod_int e = *this, res = mod_int(1);
for (; t; e *= e, t >>= 1)
if (t & 1)
res *= e;
return res;
}
mod_int fact() {
if (_fact[0].x == 0)
prepare();
return _fact[x];
}
mod_int inv_fact() {
if (_fact[0].x == 0)
prepare();
return _inv_fact[x];
}
mod_int choose(mod_int y) {
assert(y.x <= x);
return this->fact() * y.inv_fact() * mod_int(x - y.x).inv_fact();
}
static mod_int _inv[TABLE_SIZE + 1];
static mod_int _fact[TABLE_SIZE + 1];
static mod_int _inv_fact[TABLE_SIZE + 1];
static void prepare() {
_inv[1] = 1;
for (int i = 2; i <= (int)TABLE_SIZE; ++i) {
_inv[i] = 1LL * _inv[MODULO % i].x * (MODULO - MODULO / i) % MODULO;
}
_fact[0] = 1;
for (unsigned i = 1; i <= TABLE_SIZE; ++i) {
_fact[i] = _fact[i - 1] * signed(i);
}
_inv_fact[TABLE_SIZE] = _fact[TABLE_SIZE].inv();
for (int i = (int)TABLE_SIZE - 1; i >= 0; --i) {
_inv_fact[i] = _inv_fact[i + 1] * (i + 1);
}
}
};
template <signed M, unsigned F>
std::ostream &operator<<(std::ostream &os, const mod_int<M, F> &rhs) {
return os << rhs.x;
}
template <signed M, unsigned F>
std::istream &operator>>(std::istream &is, mod_int<M, F> &rhs) {
long long s;
is >> s;
rhs = mod_int<M, F>(s);
return is;
}
template <signed M, unsigned F>
mod_int<M, F> mod_int<M, F>::_inv[TABLE_SIZE + 1];
template <signed M, unsigned F>
mod_int<M, F> mod_int<M, F>::_fact[TABLE_SIZE + 1];
template <signed M, unsigned F>
mod_int<M, F> mod_int<M, F>::_inv_fact[TABLE_SIZE + 1];
template <signed M, unsigned F>
bool operator==(const mod_int<M, F> &lhs, const mod_int<M, F> &rhs) {
return lhs.x == rhs.x;
}
template <int M, unsigned F>
bool operator!=(const mod_int<M, F> &lhs, const mod_int<M, F> &rhs) {
return !(lhs == rhs);
}
const signed MF = 1000010;
const signed MOD = 1000000007;
using mint = mod_int<MOD, MF>;
mint binom(int n, int r) {
return (r < 0 || r > n || n < 0) ? 0 : mint(n).choose(r);
}
mint fact(int n) { return mint(n).fact(); }
mint inv_fact(int n) { return mint(n).inv_fact(); }
//出典 http://beet-aizu.hatenablog.com/entry/2017/12/01/225955
/*
コンストラクタ引数説明
int n_
要素数。
f
2つの要素Tをマージするための関数。
区間MAX区間更新の時: max
区間Sum区間Addの時: +
g
1つの要素Tに作用素Eを適用するための関数。
区間MAX区間更新の時: =
区間Sum区間Addの時: +
h
2つの作用素Eをマージするための関数。
区間MAX区間更新の時: =
区間Sum区間Addの時: +
T d1
演算fの単位元。
区間MAX区間更新の時: -INF
区間Sum区間Addの時: 0
E d0,
g, hの単位元。
区間MAX区間更新の時: 定義域外のどこか
区間Sum区間Addの時: 0
vector<T> v = vector<T>()
セグ木を構成するときのvector
P p = [](E a, int b) {return a; }
区間の長さbを引数に取り、区間の長さによって変化する作用素E'を返す関数。
例えば、区間MAX区間Addの時なんかは区間長によって足すべき数が変化するので必要
区間Sum区間Addの時: *
//具体例
//区間chmin, 区間min
auto myMin = [](int a, int b) {return min(a, b); };
SegmentTree<int, int> seg(n, myMin, myMin, myMin, LL_HALFMAX, LL_HALFMAX);
//区間update、区間min
SegmentTree<int, int> seg(n, myMin, myMin, myMin, LL_HALFMAX, LL_HALFMAX);
*/
template <typename T, typename E> struct SegmentTree {
typedef function<T(T, T)> F;
typedef function<T(T, E)> G;
typedef function<E(E, E)> H;
typedef function<E(E, int)> P;
int n;
F f;
G g;
H h;
P p;
T d1;
E d0;
vector<T> dat;
vector<E> laz;
SegmentTree(
int n_, F f, G g, H h, T d1, E d0, vector<T> v = vector<T>(),
P p = [](E a, int b) { return a; })
: f(f), g(g), h(h), d1(d1), d0(d0), p(p) {
init(n_);
if (n_ == (int)v.size())
build(n_, v);
}
//初期化。要素配列と遅延配列を2*n-1個にする
void init(int n_) {
n = 1;
while (n < n_)
n *= 2;
dat.clear();
dat.resize(2 * n - 1, d1);
laz.clear();
laz.resize(2 * n - 1, d0);
}
//既存のvectorからセグ木を構築
void build(int n_, vector<T> v) {
for (int i = 0; i < n_; i++)
dat[i + n - 1] = v[i];
for (int i = n - 2; i >= 0; i--)
dat[i] = f(dat[i * 2 + 1], dat[i * 2 + 2]);
}
//ノードを評価する。
inline void eval(int len, int k) {
//遅延配列に単位元が入ってたら評価済みなのでおしまい
if (laz[k] == d0)
return;
//葉ノードでないなら遅延伝播する
if (k * 2 + 1 < n * 2 - 1) {
// h: 2つの作用素を引数に取り合成した作用素を返す関数
laz[k * 2 + 1] = h(laz[k * 2 + 1], laz[k]);
laz[k * 2 + 2] = h(laz[k * 2 + 2], laz[k]);
}
// p:
// このノードに対応する区間長と作用素を引数に取り、区間長に対応する作用素を返す関数
// dat[k] にlaz に溜めていた作用素を適用(g:
// 要素型と作用素型を引数に取り、要素に作用素を作用させた結果を返す関数、ここでの作用素とは区間Sum区間Addなら
// (+ 3) とか)
dat[k] = g(dat[k], p(laz[k], len));
//適用し終わったので遅延配列をクリア
laz[k] = d0;
}
//[l,r)の区間を再帰的に見ながら0-indexedの[a, b)を更新する
T update(int a, int b, E x, int k, int l, int r) {
//先に評価
eval(r - l, k);
//範囲外ならなにもしないでそのノードが持つ値を返す
if (r <= a || b <= l)
return dat[k];
//完全被覆なら既に遅延配列に入っている作用素と追加したい作用素をマージした後にそれを要素に作用させた結果を返す、pは区間長に対応する作用素を得るための(ry
if (a <= l && r <= b) {
laz[k] = h(laz[k], x);
return g(dat[k], p(laz[k], r - l));
}
//完全被覆でも範囲外でもないなら(中途半端にかぶっているなら)完全被覆と範囲外の境界が見えるまで木を潜って変化後の値を得る
return dat[k] = f(update(a, b, x, k * 2 + 1, l, (l + r) / 2),
update(a, b, x, k * 2 + 2, (l + r) / 2, r));
}
T update(int a, int b, E x) { return update(a, b, x, 0, 0, n); }
T query(int a, int b, int k, int l, int r) {
eval(r - l, k);
//範囲外なら単位元を返す
if (r <= a || b <= l)
return d1;
//完全被覆ならそのまま返す
if (a <= l && r <= b)
return dat[k];
//一部被覆なら完全被覆と範囲外に分かれるまで木を潜る
T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return f(vl, vr);
}
// 0-indexedで[a, b)の区間*を求める
T query(int a, int b) { return query(a, b, 0, 0, n); }
};
//座標圧縮
class compress {
public:
static const int MAP = 10000000;
map<int, int> zip;
int unzip[MAP];
compress(vector<int> &x) {
sort(x.begin(), x.end());
x.erase(unique(x.begin(), x.end()), x.end());
for (int i = 0; i < x.size(); i++) {
zip[x[i]] = i;
unzip[i] = x[i];
}
}
};
unsigned euclidean_gcd(unsigned a, unsigned b) {
while (1) {
if (a < b)
swap(a, b);
if (!b)
break;
a %= b;
}
return a;
}
// https://ei1333.github.io/luzhiled/snippets/dp/cumulative-sum-2d.html
template <class T> struct CumulativeSum2D {
vector<vector<T>> data;
CumulativeSum2D(int W, int H) : data(W + 1, vector<int>(H + 1, 0)) {}
void add(int x, int y, T z) {
++x, ++y;
if (x >= data.size() || y >= data[0].size())
return;
data[x][y] += z;
}
void build() {
for (int i = 1; i < data.size(); i++) {
for (int j = 1; j < data[i].size(); j++) {
data[i][j] += data[i][j - 1] + data[i - 1][j] - data[i - 1][j - 1];
}
}
}
T query(int sx, int sy, int gx, int gy) {
return (data[gx][gy] - data[sx][gy] - data[gx][sy] + data[sx][sy]);
}
};
// lib
int nC2(int n) { return n * (n - 1) / 2; }
class node {
public:
int depth;
int num;
node(int d, int n) {
depth = d;
num = n;
}
};
CumulativeSum2D<int> sumB(4001, 4001);
template <class T> struct CumulativeSum {
vector<T> data;
CumulativeSum(int sz) : data(sz, 0){};
void add(int k, T x) { data[k] += x; }
void build() {
for (int i = 1; i < data.size(); i++) {
data[i] += data[i - 1];
}
}
T query(int k) {
if (k < 0)
return (0);
return (data[min(k, (int)data.size() - 1)]);
}
//[left, right]の和
T query(int left, int right) { return query(right) - query(left - 1); }
};
std::vector<bool> IsPrime;
void sieve(size_t max) {
if (max + 1 > IsPrime.size()) { // resizeで要素数が減らないように
IsPrime.resize(max + 1, true); // IsPrimeに必要な要素数を確保
}
IsPrime[0] = false; // 0は素数ではない
IsPrime[1] = false; // 1は素数ではない
for (size_t i = 2; i * i <= max; ++i) // 0からsqrt(max)まで調べる
if (IsPrime[i]) // iが素数ならば
for (size_t j = 2; i * j <= max; ++j) // (max以下の)iの倍数は
IsPrime[i * j] = false; // 素数ではない
}
vector<int64_t> divisor(int64_t n) {
vector<int64_t> ret;
for (int64_t i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n)
ret.push_back(n / i);
}
}
sort(begin(ret), end(ret));
return (ret);
}
// 汎用的な二分探索のテンプレ(めぐる式)
int binary_search(function<bool(int)> isOk, int ng, int ok) {
/* ok と ng のどちらが大きいかわからないことを考慮 */
while (abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isOk(mid))
ok = mid;
else
ng = mid;
}
return ok;
}
std::pair<std::vector<Weight>, bool> bellmanFord(const Graph &g, int s) {
int n = g.size();
const Weight inf = std::numeric_limits<Weight>::max() / 8;
Edges es;
for (int i = 0; i < n; i++)
for (auto &e : g[i])
es.emplace_back(e);
//初期化、スタート地点以外の距離は無限大
std::vector<Weight> dist(n, inf);
dist[s] = 0;
bool negCycle = false;
for (int i = 0;; i++) {
bool update = false;
//すべての辺について、その辺をとおった場合に最短経路が更新できる場合は更新する
for (auto &e : es) {
if (dist[e.src] != inf && dist[e.dst] > dist[e.src] + e.weight) {
dist[e.dst] = dist[e.src] + e.weight;
update = true;
}
}
//更新がなくなったらおはり
if (!update)
break;
// n回以上更新されてたら負閉路がある
if (i > n) {
negCycle = true;
break;
}
}
return std::make_pair(dist, !negCycle);
}
//ゴールを指定して、それまでのパスに負閉路がなかったらOK(これは嘘)
std::pair<std::vector<Weight>, bool> bellmanFord(const Graph &g, int s, int d) {
int n = g.size();
const Weight inf = std::numeric_limits<Weight>::max() / 8;
Edges es;
for (int i = 0; i < n; i++)
for (auto &e : g[i])
es.emplace_back(e);
//初期化、スタート地点以外の距離は無限大
std::vector<Weight> dist(n, inf);
dist[s] = 0;
bool negCycle = false;
for (int i = 0; i < n * 2; i++) {
bool update = false;
//すべての辺について、その辺をとおった場合に最短経路が更新できる場合は更新する
for (auto &e : es) {
if (dist[e.src] != inf && dist[e.dst] > dist[e.src] + e.weight) {
dist[e.dst] = dist[e.src] + e.weight;
update = true;
if (e.dst == d && i == n * 2 - 1)
negCycle = true;
}
}
//更新がなくなったらおはり
if (!update)
break;
}
return std::make_pair(dist, !negCycle);
}
// R[i] == S[i] を中心とした極大回文長 なるvector Rを返す
vector<int> Manachar(string S) {
int len = S.length();
vector<int> R(len);
int i = 0, j = 0;
while (i < S.size()) {
while (i - j >= 0 && i + j < S.size() && S[i - j] == S[i + j])
++j;
R[i] = j;
int k = 1;
while (i - k >= 0 && i + k < S.size() && k + R[i - k] < j)
R[i + k] = R[i - k], ++k;
i += k;
j -= k;
}
return R;
}
std::vector<int> tsort(const Graph &g) {
int n = g.size(), k = 0;
std::vector<int> ord(n), in(n);
for (auto &es : g)
for (auto &e : es)
in[e.dst]++;
std::queue<int> q;
//入次数0の点をキューに追加
for (int i = 0; i < n; ++i)
if (in[i] == 0)
q.push(i);
while (q.size()) {
int v = q.front();
// Sから node n を削除する
q.pop();
// L に n を追加する
ord[k++] = v;
for (auto &e : g[v]) {
//選択した点から出てる辺を削除、0になったらキューに追加
if (--in[e.dst] == 0) {
q.push(e.dst);
}
}
}
return *std::max_element(in.begin(), in.end()) == 0 ? ord
: std::vector<int>();
}
std::vector<Weight> dijkstra(const Graph &g, int s) {
const Weight INF = std::numeric_limits<Weight>::max() / 8;
using state = std::tuple<Weight, int>;
std::priority_queue<state> q;
std::vector<Weight> dist(g.size(), INF);
dist[s] = 0;
q.emplace(0, s);
while (q.size()) {
Weight d;
int v;
std::tie(d, v) = q.top();
q.pop();
d *= -1;
/* if(v == t) return d; */
if (dist[v] < d)
continue;
for (auto &e : g[v]) {
if (dist[e.dst] > dist[v] + e.weight) {
dist[e.dst] = dist[v] + e.weight;
q.emplace(-dist[e.dst], e.dst);
}
}
}
return dist;
}
Matrix WarshallFloyd(const Graph &g) {
auto const INF = std::numeric_limits<Weight>::max() / 8;
int n = g.size();
Matrix d(n, Array(n, INF));
rep(i, n) d[i][i] = 0;
rep(i, n) for (auto &e : g[i]) d[e.src][e.dst] =
std::min(d[e.src][e.dst], e.weight);
rep(k, n) rep(i, n) rep(j, n) {
if (d[i][k] != INF && d[k][j] != INF) {
d[i][j] = std::min(d[i][j], d[i][k] + d[k][j]);
}
}
return d;
}
const int BLACK = 1, WHITE = 0;
bool isValid(vector<vector<int>> &mapData, int gyo, int retu) {
bool f = true;
rep(i, gyo) {
rep(j, retu) {
int colorCnt = 0;
if (j > 0 && mapData[i][j] == mapData[i][j - 1]) {
colorCnt++;
}
if (i > 0 && mapData[i][j] == mapData[i - 1][j]) {
colorCnt++;
}
if (i < gyo - 1 && mapData[i][j] == mapData[i + 1][j]) {
colorCnt++;
}
if (j < retu - 1 && mapData[i][j] == mapData[i][j + 1]) {
colorCnt++;
}
if (colorCnt > 1) {
f = false;
}
}
}
return f;
}
void getNext(int nowX, int nowY, int *pOutX, int *pOutY, int gyo, int retu) {
if (nowX == retu - 1) {
*pOutY = nowY + 1;
*pOutX = 0;
return;
}
*pOutX = nowX + 1;
*pOutY = nowY;
}
void dfs(vector<vector<int>> mapData, int nowX, int nowY, int gyo, int retu,
int *outCnt) {
//最後まできてたら
if (nowX == retu - 1 && nowY == gyo - 1) {
mapData[nowY][nowX] = BLACK;
if (isValid(mapData, gyo, retu)) {
*outCnt = *outCnt + 1;
}
mapData[nowY][nowX] = WHITE;
if (isValid(mapData, gyo, retu)) {
*outCnt = *outCnt + 1;
}
return;
}
mapData[nowY][nowX] = BLACK;
int nextX, nextY;
getNext(nowX, nowY, &nextX, &nextY, gyo, retu);
dfs(mapData, nextX, nextY, gyo, retu, outCnt);
mapData[nowY][nowX] = WHITE;
getNext(nowX, nowY, &nextX, &nextY, gyo, retu);
dfs(mapData, nextX, nextY, gyo, retu, outCnt);
}
void dec(map<int, int> &ma, int a) {
ma[a]--;
if (ma[a] == 0) {
ma.erase(a);
}
}
int solve(bool idZeroPositive, int n, vector<int> a) {
int ans = 0;
if (idZeroPositive) {
if (a[0] <= 0) {
ans += -a[0] + 1;
a[0] = 1;
}
} else {
if (a[0] >= 0) {
ans += a[0] + 1;
a[0] = -1;
}
}
int su = 0;
rep(i, n) {
su += a[i];
if (idZeroPositive) {
if (i % 2 == 0 && su <= 0) {
ans += -su + 1;
su = 1;
}
if (i % 2 == 1 && su >= 0) {
ans += su + 1;
su = -1;
}
} else {
if (i % 2 == 1 && su <= 0) {
ans += -su + 1;
su = 1;
}
if (i % 2 == 0 && su >= 0) {
ans += su + 1;
su = -1;
}
}
}
return ans;
}
mint dp[210000];
signed main() {
int N;
cin >> N;
vector<int> C(N);
rep(i, N) { cin >> C[i]; }
vector<int> places[210000];
rep(i, 210000) { places[i].clear(); }
rep(i, N) { places[C[i]].push_back(i); }
dp[0] = 1;
REPS(i, N) {
//操作をしない、直前の分割方法の場合の数をそのまま足す
dp[i] += dp[i - 1];
int color = C[i - 1];
//今見ている色がcolor 色の何番目の要素かを求める
auto it = lower_bound(places[color].begin(), places[color].end(), i - 1);
int ind = it - places[color].begin();
if (ind > 0) {
//直近の相方
int pairInd = places[color][ind - 1];
if (i - 1 - pairInd > 1) {
dp[i] += dp[pairInd + 1];
}
}
}
cout << dp[N] << "\n";
}
| [
"assignment.change"
] | 907,201 | 907,202 | u783675879 | cpp |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.