-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1050c.cpp
More file actions
87 lines (76 loc) · 1.82 KB
/
1050c.cpp
File metadata and controls
87 lines (76 loc) · 1.82 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef priority_queue<int, vector<int>, greater<int>> pqmin;
const int MOD = 1e9+7;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return (a / gcd(a, b)) * b; }
int modpow(int a, int b, int mod = MOD) {
int res = 1;
while (b) {
if (b & 1) res = (res * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return res;
}
vector<int> sieve(int n) {
vector<int> isPrime(n + 1, 1);
isPrime[0] = isPrime[1] = 0;
for (int i = 2; i*i <= n; i++)
if (isPrime[i])
for (int j = i*i; j <= n; j += i)
isPrime[j] = 0;
return isPrime;
}
bool isPrime(int n) {
if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (int i = 5; i * i <= n; i += 6) {
if (n % i == 0 || n % (i + 2) == 0)
return false;
}
return true;
}
void solve(){
int n, m;
cin >> n >> m;
vector<pair<int,int>> v;
v.push_back({0,0});
for(int i=0;i<n;i++) {
int a,b;
cin>>a>>b;
v.push_back({a,b});
}
if (v.back().first < m)
v.push_back({m, 1 - v.back().second});
else
v.push_back({m, v.back().second});
int ans=0;
for(int i=0;i<(int)v.size()-1;i++){
int diff = v[i+1].first - v[i].first;
if(v[i+1].second != v[i].second){
if(diff % 2 == 0)
ans += diff - 1;
else
ans += diff;
}
else{
if(diff % 2 == 0)
ans += diff;
else
ans += diff - 1;
}
}
cout<<ans<<endl;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t = 1;
cin >> t;
while (t--) {
solve();
}
}