mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-27 17:56:28 +00:00
parent
eecfe2dbac
commit
0968dea630
51
S2OJ/396/396.cpp
Normal file
51
S2OJ/396/396.cpp
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
// ios::sync_with_stdio(0);
|
||||||
|
// cin.tie(nullptr);cout.tie(nullptr);
|
||||||
|
// int n,m,ans=0;cin>>m>>n;
|
||||||
|
// for (int i=1;i<=n;i++) fa[i]=i;
|
||||||
|
// for (int i=1;i<=m;i++){
|
||||||
|
// int x;cin>>x;int pos=find(x);
|
||||||
|
// merge(pos,pos-1);(ans+=pos*i)%=mod;
|
||||||
|
// }cout<<ans;return 0;
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <numeric>
|
||||||
|
|
||||||
|
using std::cin;
|
||||||
|
using std::cout;
|
||||||
|
const char endl = '\n';
|
||||||
|
|
||||||
|
const int N = 3000000;
|
||||||
|
const int mod = 1e9 + 7;
|
||||||
|
|
||||||
|
int n, m, fa[N], ans;
|
||||||
|
|
||||||
|
int find(int x) {
|
||||||
|
return fa[x] == x ? x : fa[x] = find(fa[x]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void merge(int x, int y) {
|
||||||
|
fa[find(x)] = find(y);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
cin.tie(nullptr);
|
||||||
|
|
||||||
|
cin >> n >> m;
|
||||||
|
|
||||||
|
std::iota(fa + 1, fa + m + 1, 1);
|
||||||
|
|
||||||
|
for (int i = 1, x; i <= n; i++) {
|
||||||
|
cin >> x;
|
||||||
|
|
||||||
|
int p = find(x);
|
||||||
|
|
||||||
|
merge(p, p - 1);
|
||||||
|
|
||||||
|
ans = (ans + static_cast<long long>(p) * i) % mod;
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << ans << endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
S2OJ/396/data/carrot1.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/396/data/carrot1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/396/data/carrot1.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/396/data/carrot1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/396/data/carrot10.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/396/data/carrot10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/396/data/carrot10.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/396/data/carrot10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/396/data/carrot2.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/396/data/carrot2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/396/data/carrot2.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/396/data/carrot2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/396/data/carrot3.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/396/data/carrot3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/396/data/carrot3.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/396/data/carrot3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/396/data/carrot4.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/396/data/carrot4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/396/data/carrot4.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/396/data/carrot4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/396/data/carrot5.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/396/data/carrot5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/396/data/carrot5.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/396/data/carrot5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/396/data/carrot6.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/396/data/carrot6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/396/data/carrot6.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/396/data/carrot6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/396/data/carrot7.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/396/data/carrot7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/396/data/carrot7.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/396/data/carrot7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/396/data/carrot8.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/396/data/carrot8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/396/data/carrot8.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/396/data/carrot8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/396/data/carrot9.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/396/data/carrot9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/396/data/carrot9.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/396/data/carrot9.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/396/data/ex_carrot1.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/396/data/ex_carrot1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/396/data/ex_carrot1.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/396/data/ex_carrot1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/396/data/problem.conf
(Stored with Git LFS)
Normal file
BIN
S2OJ/396/data/problem.conf
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user