版本比较
2026 CSP-J题解
正文
增加 12 行删除 15 行
36 行未改动37383940414142434448 行未改动93949596989798991005 行未改动106107108109112110111112113110 行未改动全部展开224225226227231228229230231232233234235240236237238239240132 行未改动全部展开37337437537637737837938038131 行未改动41341441541642041741841942042142542242342442842542643043143243343443543642742842943043143243343443543643736 行未改动#include <bits/stdc++.h>using namespace std;
int main() { string c1, s1, c2, s2; cin >> c1 >> s1 >> c2 >> s2; if (s1[2] == 'F') s1[2] = 'E'; if (s2[2] == 'F') s2[2] = 'E';48 行未改动
```cpp#include <bits/stdc++.h>#define int long long#define qwq ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)using namespace std;
const int N = 2e5+5;
5 行未改动int n;P a[N];
signed main() { qwq; cin >> n; for (int i=1; i<=n; i++) { cin >> a[i].x >> a[i].c; }110 行未改动全部展开
```cpp#include <bits/stdc++.h>#define int long long#define qwq ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)using namespace std;
const int N = 2e5+5;
int n, m, a[N], res = 0;int flag[N]; // 标记不可选数字,1表示不可选
signed main() { qwq; ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);; cin >> n >> m; for (int i=1; i<=n; i++) { cin >> a[i]; }132 行未改动全部展开 }}
signed main() { ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); cin >> n >> m; for (int i=1; i<=n; i++) { cin >> a[i]; last[a[i]] = i;31 行未改动int f[N]; // f[i]表示第i个位置的经过次数,这里应该只统计每个数字最后一次出现的位置// last[i]记录数字最后一次出现的位置
signed main() { qwq; ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); cin >> n >> m; for (int i=1; i<=n; i++) { cin >> a[i]; last[a[i]] = i; c[a[i]]++; c[a[i]]++; }
for (int i=1; i<=m; i++) f[last[i]] = c[i]; // 初始状态 for (int i=1; i<=m; i++) f[last[i]] = c[i]; // 初始状态
// 这里是必须正序循环,保证最前面的last[a[i]]先进行转移,也就是拓扑序。 for (int i=1; i<n; i++) { if (i == last[a[i]]) { int j = last[a[i+1]]; // 下一个跳转的位置 f[j] += f[i]; } } // 这里是必须正序循环,保证最前面的last[a[i]]先进行转移,也就是拓扑序。 for (int i=1; i<n; i++) { if (i == last[a[i]]) { int j = last[a[i+1]]; // 下一个跳转的位置 f[j] += f[i]; } } for (int i=1; i<=m; i++) cout << f[last[i]] << " "; return 0;}```