Educational Codeforces Round 29 E. Turn Off The TV
2017-09-23 22:02
344 查看
离散一下
然后检查每个点被覆盖多少次
然后再用一个数组来记录被覆盖情况的前缀和
然后检查每个点被覆盖多少次
然后再用一个数组来记录被覆盖情况的前缀和
#include <iostream> #include <algorithm> #include <sstream> #include <string> #include <queue> #include <cstdio> #include <map> #include <set> #include <utility> #include <stack> #include <cstring> #include <cmath> #include <vector> #include <ctime> #include <bitset> using namespace std; #define pb push_back #define sd(n) scanf("%d",&n) #define sdd(n,m) scanf("%d%d",&n,&m) #define sddd(n,m,k) scanf("%d%d%d",&n,&m,&k) #define sld(n) scanf("%lld",&n) #define sldd(n,m) scanf("%lld%lld",&n,&m) #define slddd(n,m,k) scanf("%lld%lld%lld",&n,&m,&k) #define sf(n) scanf("%lf",&n) #define sff(n,m) scanf("%lf 4000 %lf",&n,&m) #define sfff(n,m,k) scanf("%lf%lf%lf",&n,&m,&k) #define ss(str) scanf("%s",str) #define ans() printf("%d",ans) #define ansn() printf("%d\n",ans) #define anss() printf("%d ",ans) #define lans() printf("%lld",ans) #define lanss() printf("%lld ",ans) #define lansn() printf("%lld\n",ans) #define fansn() printf("%.10f\n",ans) #define r0(i,n) for(int i=0;i<(n);++i) #define r1(i,e) for(int i=1;i<=e;++i) #define rn(i,e) for(int i=e;i>=1;--i) #define rsz(i,v) for(int i=0;i<(int)v.size();++i) #define szz(x) ((int)x.size()) #define mst(abc,bca) memset(abc,bca,sizeof abc) #define lowbit(a) (a&(-a)) #define all(a) a.begin(),a.end() #define pii pair<int,int> #define pli pair<ll,int> #define mp make_pair #define lrt rt<<1 #define rrt rt<<1|1 #define X first #define Y second #define PI (acos(-1.0)) #define sqr(a) ((a)*(a)) typedef long long ll; typedef unsigned long long ull; const ll mod = 1000000000+7; const double eps=1e-9; const int inf=0x3f3f3f3f; const ll infl = 10000000000000000; const int maxn= 1000000+10; const int maxm = 1000+10; //Pretests passed int in(int &ret) { char c; int sgn ; if(c=getchar(),c==EOF)return -1; while(c!='-'&&(c<'0'||c>'9'))c=getchar(); sgn = (c=='-')?-1:1; ret = (c=='-')?0:(c-'0'); while(c=getchar(),c>='0'&&c<='9')ret = ret*10+(c-'0'); ret *=sgn; return 1; } vector<int>v; int l[maxn],r[maxn]; int add[maxn]; int cover[maxn]; int id(int x) { return lower_bound(all(v),x)-v.begin()+1; } int main() { #ifdef LOCAL freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); #endif // LOCAL int n; in(n); r1(i,n) { sdd(l[i],r[i]); v.pb(l[i]); v.pb(r[i]); v.pb(l[i]-1); v.pb(r[i]+1); } sort(all(v)); v.erase(unique(all(v)),v.end()); r1(i,n) { l[i] = id(l[i]); r[i] = id(r[i]); add[ l[i] ]++; add[ r[i]+1] --; } int sz = v.size(); r1(i,sz)add[i]+=add[i-1]; r1(i,sz)cover[i] = cover[i-1]+ ( add[i] == 1 ); int ans = -1; r1(i,n) { int check = cover[ r[i] ] - cover[ l[i] - 1 ]; if(!check) { ans = i; break; } } ansn(); return 0; }
相关文章推荐
- Educational Codeforces Round 29 - E. Turn Off The TV (离散化+化线成点)
- Educational Codeforces Round 29-E-Turn Off The TV(想法题)
- Educational Codeforces Round 4 D. The Union of k-Segments(★)
- Educational Codeforces Round 9-C. The Smallest String Concatenation(string)
- 【扫描线】Educational Codeforces Round 4 D. The Union of k-Segments
- Codeforces Educational Codeforces Round 27 - B - Luba And The Ticket
- Educational Codeforces Round 1 D. Igor In the Museum
- Educational Codeforces Round 1 D.Igor In the Museum(DFS)
- Educational Codeforces Round 13 A.Johny Likes Numbers && B. The Same Calendar
- Educational Codeforces Round 27 E. Fire in the City(二维离散化)
- Educational Codeforces Round 13 B. The Same Calendar 水题
- (Educational Codeforces Round 9 )The Smallest String Concatenation(排序)
- Educational Codeforces Round 22 C. The Tag Game
- 【Educational Codeforces Round 1D】【DFS 联通块打标记法】Igor In the Museum 联通块内墙的面数
- Educational Codeforces Round 23 E. Choosing The Commander (trie)
- Educational Codeforces Round 9 -- C - The Smallest String Concatenation
- Educational Codeforces Round 4 A. The Text Splitting 水题
- Educational Codeforces Round 4 D. The Union of k-Segments 排序
- Educational Codeforces Round 9 C The Smallest String Concatenation
- Educational Codeforces Round 27 B. Luba And The Ticket(模拟)