Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma comment(linker, "/STACK:65777216")
- #include <iostream>
- #include <iomanip>
- #include <cstdlib>
- #include <ctime>
- #include <cstdio>
- #include <algorithm>
- #include <cmath>
- #include <vector>
- #include <set>
- #include <stack>
- #include <map>
- #include <queue>
- #include <string>
- #include <memory.h>
- #include <iterator>
- #define mem(A,X) memset(A,X,sizeof(A))
- #define memo(A) memset(A,0,sizeof(A))
- #define forn(I,B) for (int I=1;I<=(B);I++)
- #define forg(H,V) for (int H=first[V];h;h=next[H])
- #define rep(I,B) for (int I=0;I<(B);I++)
- #define labs(X) (((X)>0)?(X):(-(X)))
- #define ropen(X) freopen(X,"r",stdin)
- #define wopen(X) freopen(X,"w",stdout)
- #define rwopen(X) freopen(X".in","r",stdin);freopen(X".out","w",stdout)
- #define pb push_back
- #define mp make_pair
- #define all(X) (X).begin(),(X).end()
- #define sqr(X) ((X)*(X))
- using namespace std;
- typedef pair <int,int> pii;
- typedef long double ld;
- typedef unsigned long long ll;
- typedef pair <ll,ll> pll;
- typedef vector<int> vi;
- const int N=5555;
- const int INF=1111111;
- const double eps=1e-9;
- const double pi=3.14159265358979;
- int n,ta[N],tb[N],buf[N+N],ptr,t[N],bg,ans=-1,cx;
- char tc[N];
- bool c[N+N],cv[N+N];
- int main(){
- // ropen("input.txt");
- scanf("%d\n",&n);
- forn(i,n){
- scanf("%d %d %c\n",&ta[i],&tb[i],&tc[i]);
- buf[++ptr]=ta[i];
- buf[++ptr]=tb[i];
- }
- buf[++ptr]=0;buf[++ptr]=1000000000;
- sort(buf+1,buf+ptr+1);ptr=0;
- forn(i,n+n+2) if (buf[i]!=buf[i+1]) t[++ptr]=buf[i];
- forn(i,n){
- int a=ta[i],b=tb[i];
- bool k=tc[i]=='b';
- forn(j,ptr){
- if (t[j]>b) break;
- if (t[j]>=a && t[j]<b) cv[j]=k;
- if (j!=ptr && t[j]>=a && t[j+1]<=b) c[j]=k;
- }
- }
- cx=-1;
- forn(i,ptr){
- if (!cv[i] && cx==-1) cx=t[i];
- if (cv[i] && cx!=-1){
- if (t[i]-cx>ans){
- bg=cx;
- ans=t[i]-cx;
- }
- cx=-1;
- }
- if (i==ptr) break;
- if (!c[i] && cx==-1 && t[i]+1!=t[i+1]) cx=t[i]+1;
- if (c[i] && cx!=-1){
- if (t[i+1]-cx>ans){
- bg=cx;
- ans=t[i]-cx;
- }
- cx=-1;
- }
- }
- if (1000000000-cx>ans) printf("%d %d\n",cx,1000000000);
- else printf("%d %d\n",bg,bg+ans);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment