10.10T2 贪心去重
万事先排序,然后找规律
思路我还是要学习,先普通的一个点,然后我们再扩张到两个的形式,然后就出来了
code:
1 #include<iostream> 2 #include<cstdio> 3 #include<algorithm> 4 #include<queue> 5 #define N 100005 6 using namespace std; 7 const long long mod=998244353; 8 struct node { 9 long long l,r; 10 bool operator<(const node&a)const{ 11 return r>a.r; 12 } 13 } e[N]; 14 bool cmp(const node&a,const node &b){ 15 return a.l<b.l; 16 } 17 long long read(){ 18 long long x=0,f=1; 19 char c=getchar(); 20 while(!isdigit(c)){ 21 if(c=='-')f=-1; 22 c=getchar(); 23 } 24 while(isdigit(c)){ 25 x=(x<<3)+(x<<1)+c-'0'; 26 c=getchar(); 27 } 28 return x*f; 29 } 30 long long ksm(long long a,long long b){ 31 long long ans=1; 32 for(;b;b>>=1){ 33 if(b&1){ 34 ans*=a; 35 ans%=mod; 36 } 37 a*=a; 38 a%=mod; 39 } 40 return ans; 41 } 42 long long a[N]; 43 priority_queue<long long,vector<long long>,greater<long long> >q; 44 int main() { 45 long long n,m; 46 n=read(),m=read(); 47 for(long long i=1; i<=n; i++){ 48 e[i].l=read(); 49 e[i].r=read(); 50 } 51 sort(e+1,e+n+1,cmp); 52 // for(long long i=1;i<=n;i++)cout<<e[i].l<<" "<<e[i].r<<'\n'; 53 for(long long i=1; i<=m; i++) { 54 a[i]=read(); 55 } 56 sort(a+1,a+m+1); 57 long long ans=0; 58 long long head=1; 59 for(long long i=1;i<=m;i++){ 60 while(!q.empty()&&q.top()<a[i])q.pop(); 61 long long chong=q.size();chong=ksm(2,chong); 62 while(head<=n&&e[head].l<=a[i]){ 63 if(e[head].r<a[i]){ 64 head++; 65 continue; 66 } 67 q.push(e[head].r); 68 head++; 69 } 70 long long now=q.size();now=ksm(2,now); 71 ans+=now-chong; 72 ans+=mod; 73 ans%=mod; 74 } 75 cout<<ans; 76 return 0; 77 }
over