Submission #3818

#TimeUsernameProblemLanguageResultExecution timeMemory
3818cki86201Evaluation (kriii1_E)C++98
0 / 1
0 ms4468 KiB
#include<stdio.h> #include<algorithm> const int M=1000000007; struct node{ int add, tot, sum; node* left, *right; node(){ left = right = 0; add=tot=sum=0; } }; struct segment{ int s,e,y,su; bool operator<(const segment &l)const{ return y<l.y; } }; struct SegmentTree{ node* root; int start, end; SegmentTree(){} SegmentTree(int start, int end):start(start),end(end){ root = new node(); } void DFS(node* n, int s, int e, int l, int r, int su) // s-e: node가 담당하는 구간, l-r: 갱신하려는 구간 { long long cnt=e-s+1; if(e < l || r < s ) return; // 구간이 겹치지 않는 경우 if(l <= s && e <= r){ n->add += su; if(!n->left){ n->sum=(cnt*n->add)%M; n->tot=(((cnt*n->add)%M)*n->add)%M; } else{ n->sum=(long long)n->left->sum+n->right->sum+(cnt*n->add)%M; n->tot=(long long)n->left->tot+n->right->tot+(n->add*((2*n->sum-(cnt*n->add)%M)%M))%M; } return; } // 나머지 if( !n->left ) n->left = new node(), n->right = new node(); int m = ( s + e ) / 2; DFS(n->left, s, m, l, r, su); DFS(n->right, m+1, e, l, r, su); n->sum=n->left->sum+n->right->sum+(cnt*n->add)%M; n->tot=n->left->tot+n->right->tot+(n->add*(2*n->sum-(cnt*n->add)%M))%M; n->sum%=M; n->tot%=M; } void insert(int left, int right,int su) { DFS(root, start, end, left, right, su); } long long read() { return root ->tot; } }Tree=SegmentTree(0,1000000500); segment data[200005]; int n; int main() { int i,a,b,c,d,e; long long ans=0; scanf("%d",&n); for(i=0;i<n;i++){ scanf("%d%d%d%d%d",&a,&b,&c,&d,&e); data[2*i].s=a; data[2*i].e=c; data[2*i].su=e; data[2*i].y=b; data[2*i+1].s=a; data[2*i+1].e=c; data[2*i+1].su=-e; data[2*i+1].y=d+1; } std::sort(data,data+2*n); Tree.insert(data[0].s,data[0].e,data[0].su); for(int i=1;i<2*n;i++){ ans+=(Tree.read()*(data[i].y-data[i-1].y))%M; Tree.insert(data[i].s,data[i].e,data[i].su); ans%=M; } ans%=M; printf("%lld",ans); }
#Verdict Execution timeMemoryGrader output
Fetching results...