题目传送门:http://codeforces.com/contest/707/problem/E
中文题面:http://blog.csdn.net/kg20006/article/details/52275809
对于每一个链单独考虑,算对于答案的贡献
时间复杂度:\(O(k \cdot {\log _2}{(n)^2} \cdot (len + q))\)
然后在算贡献那里,可以用二维树状数组
但我的代码跑了1100ms,有一份代码只跑了700ms
于是去看了看,突然想起来,这种不带修改的二维树状数组
可以把询问记下来,按照横坐标排序,然后转化为一维树状数组
好像要稍微快一点,不过我还是写的二维的
#include<iostream> #include<cstdio> #include<cstring> #include<queue> #define LL long long #define lowbit(x) ((x)&(-(x))) using namespace std; const int N = 2000+9; const int M = 4000000+9; const int INF = 1000000000; int q,head[N],Y[M],n,m,k,X[M],W[M],nxt[M],tot,x1[N],x2[N],y1[N],y2[N],tme[N]; LL mat[N][N],vout[N]; queue<int> que[N]; char pat[N]; inline int read(){ char c=getchar(); int ret=0; while (c<'0'||c>'9') c=getchar(); while (c<='9'&&c>='0') ret=ret*10+c-'0',c=getchar(); return ret; } inline void Add(int len, int num){ static int T = 0; for (int i=1;i<=len;i++) { nxt[++T] = head[num]; X[T] = read(); Y[T] = read(); W[T] = read(); head[num] = T; } } inline void modify(int x, int y, int w){ for (int j=y;j<=m;j+=lowbit(j)) for (int i=x;i<=n;i+=lowbit(i)) mat[i][j] += w; } inline LL query(int x, int y){ LL ret = 0; for (int j=y;j;j-=lowbit(j)) for (int i=x;i;i-=lowbit(i)) ret += mat[i][j]; return ret; } int main(){ n = read(); m = read(); k = read(); for (int i=1;i<=k;i++) Add(read(),i); q = read(); for (int i=1;i<=q;i++) { scanf("%s",pat+1); if (pat[1] == 'S') que[read()].push(i); else { tme[++tot] = i; x1[tot] = read(); y1[tot] = read(); x2[tot] = read(); y2[tot] = read(); } } for (int i=1;i<=k;i++) que[i].push(INF); for (int i=1;i<=k;i++) { for (int j=head[i];j;j=nxt[j]) modify(X[j],Y[j],W[j]); int sta = 1,T=1; while (!que[i].empty()) { int w = que[i].front(); que[i].pop(); sta ^= 1; while (T <= tot && tme[T] < w) { int p = T++; if (sta^1) vout[p] += query(x1[p]-1,y1[p]-1) + query(x2[p],y2[p]) - query(x1[p]-1,y2[p]) - query(x2[p],y1[p]-1); } } for (int j=head[i];j;j=nxt[j]) modify(X[j],Y[j],-W[j]); } for (int i=1;i<=tot;i++) printf("%I64d\n",vout[i]); return 0; }
I really enjoy the article.Much thanks again. Will read on…
Im grateful for the blog post.Really thank you! Awesome.
Fantastic article post.Really thank you! Awesome.
Thanks for the blog post. Great.
Very good blog.Much thanks again. Really Great.
I think this is a real great article post.Really looking forward to read more. Want more.
I appreciate you sharing this post.Much thanks again. Keep writing.
I am so grateful for your article.Thanks Again. Awesome.
Thanks for the post.Much thanks again. Will read on…
Thanks a lot for the article.Thanks Again. Want more.
Awesome article.Really looking forward to read more. Really Cool.
Thanks again for the article.Much thanks again. Really Cool.
Awesome blog article.Thanks Again. Cool.
I cannot thank you enough for the blog post.Thanks Again. Want more.
Thank you ever so for you post. Great.
This is one awesome article post. Much obliged.
Really appreciate you sharing this blog.Really thank you! Will read on…
Enjoyed every bit of your blog.Thanks Again. Really Cool.
I appreciate you sharing this post.Really thank you! Great.
Awesome blog post.Really looking forward to read more. Cool.
Im thankful for the article.Really looking forward to read more. Great.
Wow, great blog.Really looking forward to read more. Cool.
Im obliged for the blog post.Really looking forward to read more. Fantastic.
Really enjoyed this article.Thanks Again. Really Cool.
Thanks again for the blog.Much thanks again. Want more.
Great blog post.Much thanks again. Fantastic.
Great blog.Really looking forward to read more. Awesome.
Very neat blog post.Really thank you! Much obliged.
I truly appreciate this post.Thanks Again. Much obliged.
I really liked your blog post.Much thanks again.
Im thankful for the blog post.Much thanks again. Want more.
Fantastic blog post.Really thank you! Really Cool.
Enjoyed every bit of your blog article.Really thank you! Will read on…
Hey, thanks for the article post. Want more.
Say, you got a nice post. Will read on…
Appreciate you sharing, great blog.Much thanks again.
Im thankful for the post. Will read on…
Appreciate you sharing, great blog article.Really thank you! Really Cool.
Im grateful for the article.Really thank you! Much obliged.
I really enjoy the post. Will read on…
Thank you ever so for you blog article.Really looking forward to read more. Want more.
I really liked your blog.Really thank you!
Appreciate you sharing, great blog.Thanks Again. Really Cool.
Im grateful for the post.Really looking forward to read more. Will read on…
Looking forward to reading more. Great blog article. Fantastic.
Im grateful for the blog. Want more.
Muchos Gracias for your article. Cool.
I value the blog.Really thank you! Really Great.
Major thanks for the article.Really thank you!
Say, you got a nice post.Thanks Again. Fantastic.
Major thanks for the post.Much thanks again. Fantastic.
Really enjoyed this blog.Really thank you! Cool.
I am so grateful for your article. Will read on…
Really appreciate you sharing this article.Really thank you! Want more.
Fantastic post.Really thank you! Great.
Thank you ever so for you article post. Great.
Major thankies for the article post.Really thank you! Awesome.
I appreciate you sharing this blog post. Great.
Thanks again for the blog post. Really Great.
Very neat article.Really looking forward to read more. Fantastic.
I really liked your post. Want more.
Very informative blog post.Thanks Again. Great.
Thanks for sharing, this is a fantastic article post.Really looking forward to read more. Will read on…
Very neat article.Really thank you!
I cannot thank you enough for the post.Much thanks again. Keep writing.
Major thanks for the blog article.Much thanks again. Really Great.
Thanks again for the article.Really thank you! Will read on…
Im thankful for the article.Much thanks again. Want more.
Hey, thanks for the article.Really thank you! Really Great.
“4 Songs for the Club” Is a 4 song CD-EP from B-Rock, For Dj’s and Bars and Dance clubs ..”Dance”Features Rockman doing the electronic Vocals on the Chorus. A hand clapping song to get people on tha dance floor ….”Mix It With Tha Water”. Features B-Rocks Team member Pif .. Tha song is an urban street tale with a great Trap Beat….”I Like It Straight” is Bound to be a New Club/ Bar Anthem for the DJ’s to get the crowds up on their feet and to get another drink..LOL…and “Crack Them bottle (Get Fucked Up)” well that’s a story that all party goers live on the weekend! … 4 Dance Hits 4 tha Club.. a great EP for any DJ to have
Thank you ever so for you blog.Really looking forward to read more. Fantastic.
Say, you got a nice blog article.Much thanks again. Cool.
I cannot thank you enough for the article.Really thank you!
I really enjoy the article post.Much thanks again.
Muchos Gracias for your article post.Much thanks again. Fantastic.
Really appreciate you sharing this blog post. Keep writing.
Major thanks for the article.Much thanks again. Awesome.
Looking forward to reading more. Great article post.Thanks Again. Want more.
I loved your blog article.Much thanks again. Want more.
Im grateful for the post.Really thank you! Will read on…
I loved your blog article.Much thanks again. Great.
wow, awesome blog post.Really looking forward to read more. Want more.
I appreciate you sharing this blog article.Really looking forward to read more. Will read on…
Say, you got a nice blog post.Really looking forward to read more. Fantastic.
Awesome article post.Thanks Again.
I really liked your article post.Really looking forward to read more. Really Great.
I loved your blog article.Thanks Again. Great.
I am so grateful for your blog article.Really looking forward to read more. Really Cool.
Looking forward to reading more. Great blog.Much thanks again. Really Cool.
Thanks for sharing, this is a fantastic post.Really looking forward to read more. Will read on…
Say, you got a nice article post.Really thank you! Keep writing.
Thanks again for the article.Really looking forward to read more. Cool.
Looking forward to reading more. Great article.Really thank you! Fantastic.
Thanks for the blog post.Much thanks again. Will read on…
I appreciate you sharing this blog article.Much thanks again. Much obliged.
Thanks so much for the article post.Really thank you! Fantastic.
Muchos Gracias for your blog.Thanks Again.
Looking forward to reading more. Great blog post.Much thanks again. Fantastic.
Appreciate you sharing, great article.Really looking forward to read more. Cool.
Very neat post.Really thank you! Fantastic.
I truly appreciate this article.Much thanks again.
I truly appreciate this article post.Really thank you! Want more.
Major thanks for the article.Really thank you! Really Cool.
This is one awesome blog post.Much thanks again. Really Great.
Muchos Gracias for your blog post.Really thank you! Keep writing.
Great, thanks for sharing this article post.Much thanks again. Much obliged.
Very neat blog article.Much thanks again. Great.
Hey, thanks for the blog article.Thanks Again. Cool.
Say, you got a nice article.Thanks Again. Really Great.
This is one awesome blog article. Awesome.
wow, awesome post.Thanks Again. Really Cool.
I appreciate you sharing this blog post. Keep writing.
Really enjoyed this blog post.Really looking forward to read more. Great.
Thanks a lot for the blog.Thanks Again. Much obliged.
Great, thanks for sharing this article. Really Cool.
Major thanks for the blog. Really Cool.
Thank you for your article.Thanks Again. Fantastic.
Thanks a lot for the blog.Really looking forward to read more. Really Great.
I value the blog article.Really looking forward to read more.
I really liked your blog. Will read on…
Appreciate you sharing, great blog post.Much thanks again. Really Great.
Say, you got a nice post.Thanks Again. Will read on…
Fantastic article post. Much obliged.
Really appreciate you sharing this blog post.Much thanks again. Great.
Enjoyed every bit of your post.Really thank you! Want more.
Really enjoyed this blog article.Really thank you! Great.
Thanks-a-mundo for the blog article.Much thanks again. Great.
Great, thanks for sharing this blog.Really looking forward to read more. Cool.
Say, you got a nice blog article.Really thank you! Keep writing.
Thank you for your blog post.Really thank you! Keep writing.
Really informative blog article.Thanks Again. Will read on…
Thank you for your blog article.Really looking forward to read more. Cool.
Appreciate you sharing, great blog post.Thanks Again. Keep writing.
Enjoyed every bit of your blog post.Much thanks again. Fantastic.
Awesome blog article.Thanks Again. Keep writing.
Great post. Really Great.
Very neat article.Thanks Again. Great.
Im grateful for the blog.Really thank you! Will read on…
Im grateful for the article post.Thanks Again. Much obliged.
Major thanks for the article. Keep writing.
Say, you got a nice article post. Keep writing.
I loved your article post.Much thanks again. Great.
Really informative blog post.Really thank you! Fantastic.
Muchos Gracias for your blog article.Really looking forward to read more. Awesome.
I appreciate you sharing this article.Really thank you! Fantastic.
Major thanks for the blog article.Really thank you! Cool.
I value the blog article.Really thank you! Want more.
I think this is a real great blog post.Thanks Again. Cool.
Really enjoyed this article post.Thanks Again. Will read on…
Great, thanks for sharing this blog.Much thanks again. Cool.
wow, awesome article.Really thank you! Keep writing.
Wow, great blog article. Fantastic.
I need to say your site is really helpful I also love the theme, its amazing!
I think this is a real great blog post.Really thank you! Will read on…
A big thank you for your blog article.Really looking forward to read more. Keep writing.
I really enjoy the article. Really Great.
This is one awesome article post.Much thanks again. Really Great.
Wow, great blog article.Really thank you! Awesome.
I really enjoy the blog article.Really looking forward to read more. Want more.
Enjoyed every bit of your article post.Really thank you! Fantastic.
I really liked your blog post.
Thanks for sharing, this is a fantastic blog post.Thanks Again. Want more.
Thank you for your blog article.Really looking forward to read more. Much obliged.
Great article post. Really Great.
Wow, great blog post.Much thanks again. Fantastic.
Looking forward to reading more. Great post.Much thanks again. Fantastic.
Fantastic article. Will read on…
I loved your post.Thanks Again.
I really like and appreciate your blog article. Great.
Muchos Gracias for your blog.Really looking forward to read more. Awesome.
Thanks-a-mundo for the blog article. Much obliged.
Really informative blog post.Really thank you! Much obliged.
A round of applause for your blog article.Really looking forward to read more. Really Cool.
I really enjoy the post.Much thanks again. Cool.
Fantastic blog. Great.
Thank you for your blog. Fantastic.