1 solutions
-
0
C++ :
#include<iostream> #include<cstring> using namespace std; int main() { int l,m,a,b,c=0; cin>>l>>m; bool s[10001]; memset(s,1,sizeof(s)); for(int i=1;i<=m;i++) { cin>>a>>b; for(int j=a;j<=b;j++) s[j]=0; } for(int i=0;i<=l;i++) if(s[i]==1) c++; cout<<c; }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
- 17915
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By