-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathB.cpp
40 lines (39 loc) · 1.01 KB
/
B.cpp
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
#include <algorithm>
#include <iostream>
#include <cstring>
#include <climits>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#define Re register
#define LL long long
#define U unsigned
#define FOR(i,a,b) for(Re int i = a;i <= b;++i)
#define ROF(i,a,b) for(Re int i = a;i >= b;--i)
#define SFOR(i,a,b,c) for(Re int i = a;i <= b;i+=c)
#define SROF(i,a,b,c) for(Re int i = a;i >= b;i-=c)
#define CLR(i,a) memset(i,a,sizeof(i))
#define BR printf("--------------------\n")
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
#define int LL
int N;
//[a,b] [c,d]
signed main(){
scanf("%I64d",&N);
int lx=0,ly=0,ans = 1;
for(int i = 1;i <= N;i++){
int x,y;scanf("%I64d%I64d",&x,&y);
// [x,lx] [y,ly]
ans += std::max(std::min(x,y)-std::max(lx,ly)+(lx!=ly),0ll);
lx = x;ly = y;
//DEBUG(ans);
}
printf("%I64d\n",ans);
return 0;
}