区间(差分)

This commit is contained in:
James 2020-05-02 09:30:58 +08:00
parent 7e942cd5d9
commit 7e94ecda9a
9 changed files with 91 additions and 0 deletions

3
2769_qujian/Readme.md Normal file
View File

@ -0,0 +1,3 @@
# 标题
* 内容

View File

@ -0,0 +1 @@
#

BIN
2769_qujian/doc/区间.pdf Normal file

Binary file not shown.

48
2769_qujian/main.cpp Normal file
View File

@ -0,0 +1,48 @@
#include <iostream>
using namespace std;
int a[1000001]={0};
int q[1000001]={0};
bool ce[1000001]={0};
int main()
{
int n,end=0;
cin>>n;
for(int i=1;i<=n;i++){
int tou,wei;
cin>>tou>>wei;
if(tou==wei){
ce[tou]=1;
}
a[tou]++;
a[wei]--;
if(wei>end){
end=wei;
}
}
// for(int i=1;i<=n;i++){
// q[i]=a[i]+q[i-1];
// cout<<q[i]<<" ";
// }
// cout<<endl;
bool qi=0;
for(int i=1;i<=end;i++){
a[i]+=a[i-1];
if(qi==0&&a[i]>=1&&a[i-1]==0){
ce[i]=0;
cout<<i<<" ";
qi=1;
}
if(qi==1&&a[i]==0&&a[i-1]>0){
ce[i]=0;
cout<<i<<endl;
qi=0;
}
if(ce[i]==1&&a[i]==0){
if(qi==0){
cout<<i<<" ";
}
cout<<i<<endl;
qi=0;
}
}
}

BIN
2769_qujian/main.exe Normal file

Binary file not shown.

6
2769_qujian/test/in.txt Normal file
View File

@ -0,0 +1,6 @@
5
5 6
1 4
10 10
6 9
8 10

4
2769_qujian/test/in2.txt Normal file
View File

@ -0,0 +1,4 @@
3
1 1
2 3
3 3

6
2769_qujian/test/in3.txt Normal file
View File

@ -0,0 +1,6 @@
5
1 30
1 1
1 2
3 30
30 30

23
2769_qujian/test/out.txt Normal file
View File

@ -0,0 +1,23 @@
## z:\Chao\src\2769_qujian\test\in.txt
2020/05/01 ÖÜÎå 21:45:42.33
1 4
5 10
-----------------------------------------------
Process exited after 130 ms with return value 0
## z:\Chao\src\2769_qujian\test\in2.txt
2020/05/01 ÖÜÎå 21:45:42.33
1 1
2 3
-----------------------------------------------
Process exited after 90 ms with return value 0
## z:\Chao\src\2769_qujian\test\in3.txt
2020/05/01 ÖÜÎå 21:45:42.33
1 30
-----------------------------------------------
Process exited after 90 ms with return value 0