当前位置:网站首页>#796 Div.2 F. Sanae and Giant Robot set *
#796 Div.2 F. Sanae and Giant Robot set *
2022-06-28 00:33:00 【Strezia】
1688F
set,2500
The question
give a , b a,b a,b Two sequences , And give m m m Intervals [ l i , r i ] [l_i,r_i] [li,ri], You can satisfy from them every time ∑ i = l r a i = ∑ i = l r b i \sum_{i=l}^ra_i=\sum_{i=l}^rb_i ∑i=lrai=∑i=lrbi Any one of the intervals of , Execute on all numbers in this interval a i = b i a_i=b_i ai=bi, Ask if you can go through several operations , bring a a a Sequence sum b b b The same sequence ?
Ideas
An interval can be selected if and only if the sum of two sequences in this interval is the same , That is, the difference is 0, So use arrays s i s_i si Represents the difference between the prefixes of two arrays , namely s i = s i − 1 + a i − b i s_i=s_{i-1} + a_i - b_i si=si−1+ai−bi, Then interval [ l , r ] [l,r] [l,r] Can be selected if and only if s l − 1 = s r s_{l-1}=s_r sl−1=sr, And after the operation s l − 1 = s l = . . . = s r s_{l-1}=s_l=...=s_r sl−1=sl=...=sr, The ultimate goal is to make s s s The array is all 0 0 0 , So choose s l − 1 ≠ 0 s_{l-1}\neq 0 sl−1=0 It doesn't make sense .
So the question can be translated into : For interval [ l , r ] [l,r] [l,r] , If s l − 1 = s r = 0 s_{l-1}=s_{r}=0 sl−1=sr=0 , makes s l − 1 = s l = . . . = s r = 0 s_{l-1}=s_l=...=s_r=0 sl−1=sl=...=sr=0 , Is it possible to make s s s All for 0 0 0 .
It can be used queue Save array s s s Have been to 0 The location of ,set Not yet 0 The location of , The sequence traversal has been 0 The side connected by the position of , If the other point is also 0, Then traverse the range within this interval set And add to the queue . If the final team is empty but set Not empty , There is no solution. . Each point can join the queue at most once , Time complexity O ( ( n + m ) log n ) O((n+m)\log n) O((n+m)logn)
Code
int n, m;
int a[maxn], b[maxn], s[maxn];
vector<int> e[maxn];
void solve() {
cin >> n >> m;
set<int> se;
for(int i = 1; i <= n; i++) {
cin >> a[i];
se.insert(i);
}
for(int i = 1; i <= n; i++) {
cin >> b[i];
s[i] = s[i-1] + a[i] - b[i];
e[i].clear();
}
e[0].clear();
//se Express non 0 The location of
for(int i = 1; i <= m; i++) {
int x, y;
cin >> x >> y;
x--;
e[x].pb(y);
e[y].pb(x);
}
queue<int> q;
for(int i = 0; i <= n; i++) {
if(!s[i]) {
q.push(i);
se.erase(i);
}
}
while(!q.empty()) {
int x = q.front();
q.pop();
for(int i = 0; i < e[x].size(); i++) {
int y = e[x][i];
if(s[y]) continue;
int l = min(x, y), r = max(x, y);
auto itl = se.lower_bound(l), itr = se.upper_bound(r);
for(auto it = itl; it != itr; it++) {
s[*it] = 0;
q.push(*it);
}
se.erase(itl, itr);
}
}
if(!se.empty()) {
cout << "NO\n";
}
else {
cout << "YES\n";
}
}
边栏推荐
- 炼金术(4): 程序员的心智模型
- zotero文献管理工具安装使用
- The development of the Internet provides new solutions for industrial transformation
- [microservices sentinel] sentinel data persistence
- Hcip/hcie Routing & Switching / datacom Reference Dictionary Series (19) comprehensive summary of PKI knowledge points (public key infrastructure)
- 夏日的晚会
- Logging log usage
- Alchemy (1): identify prototype, demo and MVP in project development
- JVM的内存模型简介
- How many securities companies can a person open an account? Is it safe to open an account
猜你喜欢

数仓的字符截取三胞胎:substrb、substr、substring

JVM的内存模型简介

Summary of wuenda's machine learning course (14)_ Dimensionality reduction
![[idea] idea formatting code skills](/img/06/38079517e901bc48dc4ca0f8cc63fe.jpg)
[idea] idea formatting code skills

A summer party

Sword finger offer 61 Shunzi in playing cards

【论文阅读|深读】SDNE:Structural Deep Network Embedding

本地可视化工具连接阿里云centOS服务器的redis

剑指 Offer 61. 扑克牌中的顺子
![计数质数[枚举 -> 空间换时间]](/img/11/c52e1dfce8e35307c848d12ccc6454.png)
计数质数[枚举 -> 空间换时间]
随机推荐
Eliminate gaps around El image images
TIME_ Solutions to excessive wait
软件工程作业设计(1): [个人项目] 实现一个日志查看页面
Code neatness -- format
炼金术(6): 可迭代的模型和用例
Efficient supplier management in supply chain
Pytorch Foundation (1)
[黑苹果系列] M910x完美黑苹果系统安装教程 – 2 制作系统U盘-USB Creation
【论文阅读|深读】SDNE:Structural Deep Network Embedding
Validaterequest= "false" is a "suggestion collection" for what
什么是cookie,以及v-htm的安全性隐患
Character interception triplets of data warehouse: substrb, substr, substring
Mongodb- install a mongodb database locally on the windows computer
Alchemy (6): iteratable models and use cases
Scu| gait switching and target navigation of micro swimming robot through deep reinforcement learning
Modern programming languages: zig
Summary of wuenda's machine learning course (14)_ Dimensionality reduction
RNA SEQ introduction practice (I): upstream data download, format conversion and quality control cleaning
Startup and shutdown of Oracle Database
炼金术(3): 怎样做好1个业务流程的接口对接