JZOJ5892. 【NOIP2018模擬10.4】礦石
阿新 • • 發佈:2018-12-13
題解
關鍵問題是如何避免跟之前的重複。 首先,現將所以的採礦點排序。 對於一個採礦點,它不能只選擇與它前面一個相鄰的採礦點公共的礦來採, 因為這樣會跟前一個採礦點重複。 所以,對於一個採礦點,必須至少選一個在前面完全沒有出現過的採礦點。 設第i個採礦點與前面所有采礦點不同礦數為,與前面一個採礦點相同的數目是 那麼這個採礦點貢獻的方案數就是
code
#include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <cmath> #define ll long long #define N 100003 #define M 103 #define P putchar #define G getchar using namespace std; char ch; void read(int &n) { n=0; ch=G(); while((ch<'0' || ch>'9') && ch!='-')ch=G(); ll w=1; if(ch=='-')w=-1,ch=G(); while('0'<=ch && ch<='9')n=(n<<3)+(n<<1)+ch-'0',ch=G(); n*=w; } const int mo=998244353; int l[N],r[N],a[N],s[N]; int n,m,sum[N],id1,id2; ll ans; ll ksm(ll x,int y) { ll s=1; for(;y;y>>=1,x=x*x%mo) if(y&1)s=s*x%mo; return s; } int main() { freopen("ore.in","r",stdin); freopen("ore.out","w",stdout); read(n);read(m); for(int i=1;i<=n;i++) read(l[i]),read(r[i]); for(int i=1;i<=m;i++)read(a[i]); sort(a+1,a+1+m); for(int i=1;i<=n;i++) { id1=lower_bound(a+1,a+1+m,l[i])-a; id2=upper_bound(a+1,a+1+m,r[i])-a; if(a[id1]<=r[i])s[id1]++; if(id1<id2)sum[id1+1]++,sum[id2]--; } for(int i=1;i<=m;i++) { sum[i]=sum[i-1]+sum[i]; ans=(ans+(ksm(2,s[i])-1+mo)%mo*ksm(2,sum[i])%mo)%mo; } printf("%lld",ans); return 0; }