forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathH.cpp
More file actions
70 lines (64 loc) · 1.51 KB
/
H.cpp
File metadata and controls
70 lines (64 loc) · 1.51 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <bits/stdc++.h>
using namespace std;
const int BASE = int(1e9) + 7;
int a[222][222];
long long ways[222][222];
int main()
{
freopen("settling.in", "r", stdin);
freopen("settling.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0);
int n, m, q, x, y;
char t;
cin >> n >> m;
while (m--)
{
cin >> x >> y;
a[x][y] = 1;
}
int ans = 0;
for (int x = n; x; x--)
{
ways[x][x] = 1;
for (int y = x + 1; y <= n; y++)
if (a[x][y])
for (int z = y; z <= n; z++)
ways[x][z] = (ways[x][z] + ways[y][z]) % BASE;
for (int y = x + 1; y <= n; y++)
ans += ways[x][y] > 0;
}
cout << ans << endl;
cin >> q;
while (q--)
{
cin >> t >> x >> y;
if (t == '?') cout << (ways[x][y] ? "YES" : "NO") << '\n';
else if (t == '+')
{
if (!a[x][y])
for (int u = 1; u <= x; u++)
for (int v = y; v <= n; v++)
{
ans -= ways[u][v] > 0;
ways[u][v] = (ways[u][v] + ways[u][x] * ways[y][v]) % BASE;
ans += ways[u][v] > 0;
}
a[x][y] = 1;
cout << ans << '\n';
}
else
{
if (a[x][y])
for (int u = 1; u <= x; u++)
for (int v = y; v <= n; v++)
{
ans -= ways[u][v] > 0;
ways[u][v] = (ways[u][v] - ways[u][x] * ways[y][v] % BASE + BASE) % BASE;
ans += ways[u][v] > 0;
}
a[x][y] = 0;
cout << ans << '\n';
}
}
}