Codeforces 915 E Physical Education Lessons

題目描述

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肯定不能用普通的線段樹做,雖然可能離散化完了之后會有奇淫技巧能做。。。。
但是我首先想到的是動態開點直接打標機下傳、、、畢竟線段樹一次操作涉及的節點數是log n級別的,就算是區間操作+需要標記下傳的話,
需要的空間也只是常數大了大,復雜度依然是log n的,而且很多操作還會有重復的區間呢。

于是我就動態開點+線段樹打tag瞎做了做,,,本地垃圾筆記本3s才能過極端數據,,,,不過codeforces的評測機跑的飛快,硬生生的縮成了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;
}

?

轉載于:https://www.cnblogs.com/JYYHH/p/8406106.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/390250.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/390250.shtml
英文地址,請注明出處:http://en.pswp.cn/news/390250.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

JDK 11 還有一個處于計劃階段的 JEP:讓其支持 TLS 1.3

開發四年只會寫業務代碼&#xff0c;分布式高并發都不會還做程序員&#xff1f; >>> JDK 11 最近有什么消息&#xff1f;我們不妨來看一下它的進展情況&#xff0c;包括最新的 JEP 提案。Java 的新版本發布計劃意味著總會有一款新的 JDK 即將推出。根據他們的計劃&a…

498. 對角線遍歷

498. 對角線遍歷 給定一個含有 M x N 個元素的矩陣&#xff08;M 行&#xff0c;N 列&#xff09;&#xff0c;請以對角線遍歷的順序返回這個矩陣中的所有元素&#xff0c;對角線遍歷如下圖所示。 示例: 輸入: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] 輸出: [1,2,4,7,5…

軟件測試測試用例編寫_不要先編寫所有軟件測試-只需編寫一個

軟件測試測試用例編寫Test Driven Development (TDD) is sometimes described as “writing tests first”. The TDD mantra states that we should not write code before we have written automated tests that exercise that code. Writing code first is considered subopt…

練習五

1.團隊模式和團隊的開發模式有什么關系&#xff1f; 答&#xff1a; 首先我來解釋一下這兩個名詞&#xff1a; 我查資料了解了一下&#xff0c;團隊模式&#xff0c;更偏向于多人合作的那種&#xff0c;而且我理解的“團隊”會是一種多人合作的情況下&#xff0c;長期磨合后的一…

Squid 訪問控制配置

Squid 訪問控制配置 主配置文件內加入限制參數 vim /etc/squid/squid.conf # 訪問控制 acl http proto HTTP # 限制訪問 good_domain添加兩個域名“.”表示半解析(相當于*) acl good_domain dstdomain .kevin.net .baidu.com # 允許good_domain內的域名訪問 http_access allow …

劍指 Offer 62. 圓圈中最后剩下的數字

0,1,,n-1這n個數字排成一個圓圈&#xff0c;從數字0開始&#xff0c;每次從這個圓圈里刪除第m個數字&#xff08;刪除后從下一個數字開始計數&#xff09;。求出這個圓圈里剩下的最后一個數字。 例如&#xff0c;0、1、2、3、4這5個數字組成一個圓圈&#xff0c;從數字0開始每…

rust 編程入門_面向初學者的Rust –最受歡迎的編程語言入門

rust 編程入門Rust has been voted Stack Overflow’s most loved programming language for five years in a row. This article will tell you why Rust is awesome.Rust已連續五年被評為Stack Overflow最受歡迎的編程語言。 本文將告訴您為什么Rust很棒。 Rust is a system…

【轉載】springboot:如何優雅的使用mybatis

這兩天啟動了一個新項目因為項目組成員一直都使用的是mybatis&#xff0c;雖然個人比較喜歡jpa這種極簡的模式&#xff0c;但是為了項目保持統一性技術選型還是定了 mybatis。到網上找了一下關于spring boot和mybatis組合的相關資料&#xff0c;各種各樣的形式都有&#xff0c;…

創建react應用程序_通過構建電影搜索應用程序在1小時內了解React

創建react應用程序If youve been meaning to learn React but are unsure of where to start, Scrimbas brand new Build a Movie Search App course is perfect for you! 如果您一直想學習React&#xff0c;但是不確定從哪里開始&#xff0c;那么Scrimba全新的Build a Movie S…

GeoServer自動發布地圖服務

1 NetCDF氣象文件自動發布案例 GeoServer是一個地理服務器&#xff0c;提供了管理頁面進行服務發布&#xff0c;樣式&#xff0c;切片&#xff0c;圖層預覽等一系列操作&#xff0c;但是手動進行頁面配置有時并不滿足業務需求&#xff0c;所以GeoServer同時提供了豐富的rest接口…

selenium+ python自動化--斷言assertpy

前言&#xff1a; 在對登錄驗證時&#xff0c;不知道為何原因用unittest的斷言不成功&#xff0c;就在網上發現這個assertpy&#xff0c;因此做個筆記 準備&#xff1a; pip install assertypy 例子&#xff1a; 1 from assertpy import assert_that2 3 4 def check_login():5 …

11. 盛最多水的容器

11. 盛最多水的容器 給你 n 個非負整數 a1&#xff0c;a2&#xff0c;…&#xff0c;an&#xff0c;每個數代表坐標中的一個點 (i, ai) 。在坐標內畫 n 條垂直線&#xff0c;垂直線 i 的兩個端點分別為 (i, ai) 和 (i, 0) 。找出其中的兩條線&#xff0c;使得它們與 x 軸共同構…

深入理解ES6 pdf

下載地址&#xff1a;網盤下載目錄 第1章 塊級作用域綁定 1var聲明及變量提升&#xff08;Hoisting&#xff09;機制 1塊級聲明 3-- let聲明 3-- 禁止重聲明 4-- const聲明 4-- 臨時死區&#xff08;Temporal Dead Zone&#xff09; 6循環中的塊作用域綁定 7-- 循環中的函…

MyBatis之輸入與輸出(resultType、resultMap)映射

2019獨角獸企業重金招聘Python工程師標準>>> 在MyBatis中&#xff0c;我們通過parameterType完成輸入映射(指將值映射到sql語句的占位符中&#xff0c;值的類型與dao層響應方法的參數類型一致)&#xff0c;通過resultType完成輸出映射(從數據庫中輸出&#xff0c;通…

2021-08-25556. 下一個更大元素 III

556. 下一個更大元素 III 給你一個正整數 n &#xff0c;請你找出符合條件的最小整數&#xff0c;其由重新排列 n 中存在的每位數字組成&#xff0c;并且其值大于 n 。如果不存在這樣的正整數&#xff0c;則返回 -1 。 注意 &#xff0c;返回的整數應當是一個 32 位整數 &…

gradle tool升級到3.0注意事項

Gradle版本升級 其實當AS升級到3.0之后&#xff0c;Gradle Plugin和Gradle不升級也是可以繼續使用的&#xff0c;但很多新的特性如&#xff1a;Java8支持、新的依賴匹配機制、AAPT2等新功能都無法正常使用。 Gradle Plugin升級到3.0.0及以上&#xff0c;修改project/build.grad…

如何使用React,TypeScript和React測試庫創建出色的用戶體驗

Im always willing to learn, no matter how much I know. As a software engineer, my thirst for knowledge has increased a lot. I know that I have a lot of things to learn daily.無論我知道多少&#xff0c;我總是愿意學習。 作為軟件工程師&#xff0c;我對知識的渴望…

PowerDesigner常用設置

2019獨角獸企業重金招聘Python工程師標準>>> 使用powerdesigner進行數據庫設計確實方便&#xff0c;以下是一些常用的設置 附加&#xff1a;工具欄不見了 調色板(Palette)快捷工具欄不見了 PowerDesigner 快捷工具欄 palette 不見了&#xff0c;怎么重新打開&#x…

bzoj5090[lydsy11月賽]組題

裸的01分數規劃,二分答案,沒了. #include<cstdio> #include<algorithm> using namespace std; const int maxn100005; int a[maxn]; double b[maxn]; double c[maxn]; typedef long long ll; ll gcd(ll a,ll b){return (b0)?a:gcd(b,a%b); } int main(){int n,k;s…

797. 所有可能的路徑

797. 所有可能的路徑 給你一個有 n 個節點的 有向無環圖&#xff08;DAG&#xff09;&#xff0c;請你找出所有從節點 0 到節點 n-1 的路徑并輸出&#xff08;不要求按特定順序&#xff09; 二維數組的第 i 個數組中的單元都表示有向圖中 i 號節點所能到達的下一些節點&#…