1 solutions
-
0
C++ :
#include<iostream> #include<cstring> using namespace std; bool a[10010]; int l,m,tot=0; int main() { memset(a,0,sizeof(a)); int x,y; cin>>l>>m; for(int i=1;i<=m;++i) { cin>>x>>y; for(int j=x;j<=y;++j)a[j]=true; } for(int i=0;i<=l;++i)if(!a[i])tot++; cout<<tot<<endl; return 0; }Pascal :
type rec=record x,y,l,r,c:longint; end; var ans,l,m,i,x,y,tot:longint; tree:array[0..40000] of rec; procedure make(l,r:longint); var now:longint; begin inc(tot); now:=tot; tree[now].x:=l; tree[now].y:=r; if l+1<=r then begin tree[now].l:=tot+1; make(l,(l+r) div 2); tree[now].r:=tot+1; make((l+r) div 2+1,r); end; end; procedure insert(v,x,y:longint); begin if (x<=tree[v].x)and(tree[v].y<=y) then begin inc(tree[v].c); exit; end; if x<=(tree[v].x+tree[v].y) div 2 then insert(tree[v].l,x,y); if y>(tree[v].x+tree[v].y) div 2 then insert(tree[v].r,x,y); end; procedure find(v:longint); begin if v=0 then exit; if tree[v].c>0 then begin inc(ans,tree[v].y-tree[v].x+1); exit; end; find(tree[v].l); find(tree[v].r); end; begin readln(l,m); make(1,l+1); for i:=1 to m do begin readln(x,y); insert(1,x+1,y+1); end; find(1); //writeln(ans,' ',l); writeln(l+1-ans); end.
- 1
Information
- ID
- 20031
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By