ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#197459 | #3447. 远恋 | smwtcat | 100 | 466ms | 6340kb | C++11 | 2.2kb | 2023-11-12 11:02:48 | 2023-11-12 13:18:21 |
answer
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef array<int, 3> ai3;
const ll inf = 0x3f3f3f3f3f3f3f3fll;
const int Mod = 1e9 + 7;
const int inv2 = (Mod+1) / 2;
inline int sign(int a){ return (a&1) ? (Mod-1) : 1; }
inline void uadd(int &a, int b){ a += b-Mod; a += (a>>31) & Mod; }
inline void usub(int &a, int b){ a -= b, a += (a>>31) & Mod; }
inline void umul(int &a, int b){ a = (int)(1ll * a * b % Mod); }
inline int add(int a, int b){ a += b-Mod; a += (a>>31) & Mod; return a; }
inline int sub(int a, int b){ a -= b, a += (a>>31) & Mod; return a; }
inline int mul(int a, int b){ a = (int)(1ll * a * b % Mod); return a; }
int qpow(int b, int p){ int ret = 1; while(p){ if(p&1) umul(ret, b); umul(b, b), p >>= 1; } return ret; }
const int fN = 111;
int fact[fN], invfact[fN], pw2[fN], invpw2[fN];
void initfact(int n){
pw2[0] = 1; for(int i = 1; i <= n; ++i) pw2[i] = mul(pw2[i-1], 2);
invpw2[0] = 1; for(int i = 1; i <= n; ++i) invpw2[i] = mul(invpw2[i-1], (Mod+1) / 2);
fact[0] = 1; for(int i = 1; i <= n; ++i) fact[i] = mul(fact[i-1], i);
invfact[n] = qpow(fact[n], Mod-2); for(int i = n; i > 0; --i) invfact[i-1] = mul(invfact[i], i);
}
int binom(int n, int m){ return (m < 0 || m > n) ? 0 : mul(fact[n], mul(invfact[m], invfact[n-m])); }
const double pi = acos(-1);
inline void chmax(int &a, int b){ (b>a) ? (a=b) : 0; }
inline void chmin(int &a, int b){ (b<a) ? (a=b) : 0; }
int n, m, deg[100100];
set< pii > st;
int main(){
//freopen("ex_love4.in", "r", stdin);
//freopen("love.out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
int ans = 0;
while(m--){
int tp, u, v;
cin >> tp >> u >> v;
--u, --v;
if(u > v) swap(u, v);
if(tp == 1){
if(!st.count(make_pair(u, v))){
ans -= (deg[u] > 0), ans -= (deg[v] > 0);
++ans, ++deg[u], ++deg[v];
st.insert(make_pair(u, v));
}
} else {
if(st.count(make_pair(u, v))){
--ans, --deg[u], --deg[v];
st.erase(make_pair(u, v));
ans += (deg[u] > 0), ans += (deg[v] > 0);
}
}
cout << ans << "\n";
}
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 23ms
memory: 1268kb
input:
2 100000 1 2 1 2 1 2 1 1 2 1 1 2 1 2 1 2 2 1 2 2 1 2 1 2 2 2 1 2 1 2 1 1 2 2 1 2 2 1 2 2 2 1 1 2 1 1...
output:
1 0 1 1 1 0 0 0 0 0 1 0 0 0 1 1 0 1 0 0 1 1 1 0 1 1 0 0 1 0 0 0 0 1 0 1 1 1 1 0 0 0 0 1 0 0 0 1 0 1 ...
result:
ok 100000 numbers
Test #2:
score: 10
Accepted
time: 26ms
memory: 1272kb
input:
2 100000 2 1 2 2 1 2 2 2 1 2 2 1 1 1 2 1 1 2 1 1 2 1 2 1 2 1 2 1 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2...
output:
0 0 0 0 1 1 1 1 0 1 0 0 0 0 0 0 0 0 1 1 1 0 0 0 1 0 1 0 0 1 1 1 1 0 0 1 0 1 1 1 1 0 1 1 1 1 1 0 1 0 ...
result:
ok 100000 numbers
Test #3:
score: 10
Accepted
time: 0ms
memory: 1328kb
input:
2000 2000 1 964 329 2 1284 1313 1 787 509 2 945 658 1 1053 1194 1 1964 1595 2 1504 1111 2 1425 469 2...
output:
1 1 2 2 3 4 4 4 4 5 5 6 6 7 8 9 10 11 12 12 13 14 15 16 17 17 18 19 20 20 20 21 21 22 22 23 23 23 24...
result:
ok 2000 numbers
Test #4:
score: 10
Accepted
time: 0ms
memory: 1320kb
input:
2000 2000 2 315 602 1 649 1798 2 26 785 1 586 1610 2 1854 883 1 1861 622 2 756 1668 2 687 98 2 1619 ...
output:
0 1 1 2 2 3 3 3 3 4 5 6 6 7 8 9 10 11 11 12 12 13 14 15 16 16 16 16 16 16 16 17 18 18 19 20 21 22 23...
result:
ok 2000 numbers
Test #5:
score: 10
Accepted
time: 2ms
memory: 1700kb
input:
100000 2000 1 92779 34174 2 24442 50350 2 95908 70204 1 24040 90714 1 72654 11859 2 92767 96242 1 72...
output:
1 1 1 2 3 3 4 4 5 5 6 6 7 8 8 9 9 10 11 11 12 12 13 13 14 15 15 15 16 17 17 18 19 20 20 20 20 20 21 ...
result:
ok 2000 numbers
Test #6:
score: 10
Accepted
time: 0ms
memory: 1700kb
input:
100000 2000 2 51154 58009 2 60818 30639 1 19247 71910 2 14664 29829 1 4253 44694 1 32318 94691 2 939...
output:
0 0 1 1 2 3 3 4 4 5 6 7 7 7 7 8 8 9 10 11 11 11 12 13 13 14 15 15 16 16 17 18 18 18 19 19 20 20 20 2...
result:
ok 2000 numbers
Test #7:
score: 10
Accepted
time: 77ms
memory: 6336kb
input:
100000 99999 1 83203 7892 1 89609 30806 1 17204 58475 1 94078 40656 1 12175 54519 1 96583 57951 1 64...
output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3...
result:
ok 99999 numbers
Test #8:
score: 10
Accepted
time: 132ms
memory: 6340kb
input:
100000 99999 1 60027 76791 1 94226 32512 1 43832 3682 1 52120 92287 1 39908 42152 1 29887 44511 1 74...
output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3...
result:
ok 99999 numbers
Test #9:
score: 10
Accepted
time: 110ms
memory: 3992kb
input:
100000 100000 2 74884 54626 2 10396 73081 1 18384 59139 1 48884 27924 1 2340 74923 2 38603 14867 1 9...
output:
0 0 1 2 3 3 4 4 4 4 4 4 4 4 4 5 5 6 7 7 8 8 9 9 9 9 9 10 11 11 11 11 11 11 12 13 13 14 15 15 16 16 1...
result:
ok 100000 numbers
Test #10:
score: 10
Accepted
time: 96ms
memory: 4000kb
input:
100000 100000 1 68584 71139 1 62909 25950 1 81680 54537 1 25264 95674 1 16361 23965 1 81367 39665 1 ...
output:
1 2 3 4 5 6 7 8 9 9 10 10 10 11 11 11 11 12 13 13 14 14 15 15 15 16 17 18 18 18 19 20 20 20 20 20 20...
result:
ok 100000 numbers
Extra Test:
score: 0
Extra Test Passed