日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Codeforces 915 E Physical Education Lessons

發(fā)布時間:2023/11/30 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Codeforces 915 E Physical Education Lessons 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

題目描述

This year Alex has finished school, and now he is a first-year student of Berland State University. For him it was a total surprise that even though he studies programming, he still has to attend physical education lessons. The end of the term is very soon, but, unfortunately, Alex still hasn't attended a single lesson!

Since Alex doesn't want to get expelled, he wants to know the number of working days left until the end of the term, so he can attend physical education lessons during these days. But in BSU calculating the number of working days is a complicated matter:

There are?nn?days left before the end of the term (numbered from?11?to?nn?), and initially all of them are working days. Then the university staff sequentially publishes?qq?orders, one after another. Each order is characterised by three numbers?ll?,?rr?and?kk?:

  • If?k=1k=1?, then all days from?ll?to?rr?(inclusive) become non-working days. If some of these days are made working days by some previous order, then these days still become non-working days;
  • If?k=2k=2?, then all days from?ll?to?rr?(inclusive) become working days. If some of these days are made non-working days by some previous order, then these days still become working days.

Help Alex to determine the number of working days left after each order!

輸入輸出格式

輸入格式:

?

The first line contains one integer?nn?, and the second line — one integer?qq?(?1<=n<=10^{9}1<=n<=109?,?1<=q<=3·10^{5}1<=q<=3?105) — the number of days left before the end of the term, and the number of orders, respectively.

Then?qq?lines follow,?ii?-th line containing three integers?l_{i}li??,?r_{i}ri??and?k_{i}ki??representing?ii?-th order (?1<=l_{i}<=r_{i}<=n1<=li?<=ri?<=n?,?1<=k_{i}<=21<=ki?<=2?).

?

輸出格式:

?

Print?qq?integers.?ii?-th of them must be equal to the number of working days left until the end of the term after the first?iiorders are published.

?

輸入輸出樣例

輸入樣例#1:?
4 6 1 2 1 3 4 1 2 3 2 1 3 2 2 4 1 1 4 2 輸出樣例#1:? 2 0 2 3 1 4

下午去湘江邊的橘子洲van了一圈,然而明天就要去雅禮報道了hhhh


很明顯n<=10^9肯定不能用普通的線段樹做,雖然可能離散化完了之后會有奇淫技巧能做。。。。
但是我首先想到的是動態(tài)開點直接打標(biāo)機(jī)下傳、、、畢竟線段樹一次操作涉及的節(jié)點數(shù)是log n級別的,就算是區(qū)間操作+需要標(biāo)記下傳的話,
需要的空間也只是常數(shù)大了大,復(fù)雜度依然是log n的,而且很多操作還會有重復(fù)的區(qū)間呢。

于是我就動態(tài)開點+線段樹打tag瞎做了做,,,本地垃圾筆記本3s才能過極端數(shù)據(jù),,,,不過codeforces的評測機(jī)跑的飛快,硬生生的縮成了300+ms。


#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<algorithm> #include<cmath> #define ll long long #define maxn 200005 using namespace std; struct node{int lc,rc;int tag,sum; }nil[maxn*71]; int n,le,ri,tot; int q,opt,cnt=1;inline void work(int v,int tmp,int len){if(tmp==-1) nil[v].tag=-1,nil[v].sum=0;else nil[v].tag=1,nil[v].sum=len; }inline void pushdown(int o,int l,int r){int ls=nil[o].lc,rs=nil[o].rc,mid=l+r>>1;if(nil[o].tag==-1){nil[o].tag=0;work(ls,-1,mid-l+1);work(rs,-1,r-mid);}else if(nil[o].tag==1){nil[o].tag=0;work(ls,1,mid-l+1);work(rs,1,r-mid);} }void update(int u,int l,int r){if(l>=le&&r<=ri){int pre=nil[u].sum;work(u,opt,r-l+1);tot+=nil[u].sum-pre;return;}if(!nil[u].lc) nil[u].lc=++cnt;if(!nil[u].rc) nil[u].rc=++cnt;pushdown(u,l,r);int mid=l+r>>1;if(le<=mid) update(nil[u].lc,l,mid);if(ri>mid) update(nil[u].rc,mid+1,r);nil[u].sum=nil[nil[u].lc].sum+nil[nil[u].rc].sum; }int main(){ // freopen("data.in","r",stdin); // freopen("data.out","w",stdout);int root=1;nil[1]=(node){0,0,0,0};scanf("%d%d",&n,&q);while(q--){scanf("%d%d%d",&le,&ri,&opt);opt=(opt==2?-1:1);update(root,1,n);printf("%d\n",n-tot);}return 0; }

?

轉(zhuǎn)載于:https://www.cnblogs.com/JYYHH/p/8406106.html

總結(jié)

以上是生活随笔為你收集整理的Codeforces 915 E Physical Education Lessons的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。