1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| #include<bits/stdc++.h> using namespace std;
#define int long long
void read(int &x) { x=0;int f=1;char ch=getchar(); for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f; for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f; }
void print(int x) { if(x<0) putchar('-'),x=-x; if(!x) return ;print(x/10),putchar(x%10+48); } void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}
#define lf double #define ll long long
#define pii pair<int,int > #define vec vector<int >
#define pb push_back #define mp make_pair #define fr first #define sc second
#define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++)
const int maxn = 1e6+10; const int inf = 1e9; const lf eps = 1e-8; const int mod = 998244353; const int inv2 = 499122177;
int n,m; vector<pii > t[62],s[62],ans,t2[62],s2[62];
void get(int l,int r,int x,int y,int d,int op) { if(op) s[d].pb(mp(l,r)); else t2[d].pb(mp(l,r)); if(x<=l&&r<=y) { if(!op) t[d].pb(mp(l,r)); else s2[d].pb(mp(l,r)); return ; } int mid=(l+r)>>1; if(x<=mid) get(l,mid,x,y,d+1,op); if(y>mid) get(mid+1,r,x,y,d+1,op); }
int get_sum(int l,int r) {return (l+r)%mod*((r-l+1)%mod)%mod*inv2%mod;}
signed main() { read(n); for(int i=1,l,r;i<=n;i++) read(l),read(r),get(0,(1ll<<60)-1,l,r,1,0); read(m); for(int i=1,l,r;i<=m;i++) read(l),read(r),get(0,(1ll<<60)-1,l,r,1,1); for(int i=1;i<=61;i++) for(auto x:t[i]) for(auto y:s[i]) ans.pb(mp(x.fr^y.fr,(x.fr^y.fr)+x.sc-x.fr)); for(int i=1;i<=61;i++) for(auto x:t2[i]) for(auto y:s2[i]) ans.pb(mp(x.fr^y.fr,(x.fr^y.fr)+x.sc-x.fr)); sort(ans.begin(),ans.end()); int p=0,res=0; for(auto x:ans) { p=max(p,x.fr-1); if(x.sc>p) res=(res+get_sum(p+1,x.sc))%mod,p=x.sc; }write(res); return 0; }
|