Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using pii = pair <int, int>;
- int red, green, blue;
- void cal(int val, int l){
- if(val % 3 == 1) red += l;
- else if(val % 3 == 2) green += l;
- else blue += l;
- }
- int main(){
- int n, m;
- scanf("%d%d", &n, &m);
- pii S[2*m + 1];
- for(int i=1;i<=m;i++){
- int a, b;
- scanf("%d%d", &a, &b);
- S[2*i - 1].first = a;
- S[2*i - 1].second = 1;
- S[2*i].first = b+1;
- S[2*i].second = 2;
- }
- char a;
- scanf(" %c", &a);
- sort(S + 1, S + 2*m + 1);
- int s = 1, val = 1;
- for(int i=1;i<=2*m;i++){
- int idx = S[i].first, opr = S[i].second;
- cal(val % 3, idx - s);
- s = idx;
- if(opr == 1) val ++;
- else val --;
- }
- cal(val, n + 1 - s);
- int sum;
- if(a == 'R') sum = (green * 2) + blue;
- else if(a == 'G') sum = red + (blue * 2);
- else sum = (red * 2) + green;
- printf("%d", sum);
- return 0;
- }
- /*
- 6 1
- 3 3
- G
- 10 7
- 1 3
- 2 8
- 6 9
- 3 5
- 6 9
- 1 5
- 2 8
- R
- 10 4
- 1 3
- 3 5
- 5 7
- 7 9
- R
- 10 4
- 1 4
- 3 4
- 2 6
- 4 8
- G
- 10 5
- 1 10
- 3 5
- 6 9
- 1 6
- 3 9
- B
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement