当前位置: 首页 > news >正文

Codeforces Round 977 (Div. 2) C2 Adjust The Presentation (Hard Version)(思维,set)

题目链接

Codeforces Round 977 (Div. 2) C2 Adjust The Presentation (Hard Version)

思路

我们令 s [ i ] s[i] s[i]表示第 i i i名成员最早上场的时间。

显然,只有当 s s s数组单调不减时才会有解。

换句话说,只有 s [ i ] ≤ s [ i + 1 ] s[i] \le s[i+1] s[i]s[i+1]时才有解。

因此,我们可以使用 s e t set set来动态维护有多少个 s [ i ] ≤ s [ i + 1 ] s[i] \le s[i+1] s[i]s[i+1],当 s e t set set的大小为 0 0 0时有解,否则无解。

代码

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 5;
const int mod = 998244353;
const int inf = 1e6;
int n, m, q;
int a[N], b[N], s[N], idx[N];
void solve()
{cin >> n >> m >> q;for (int i = 1; i <= n; i++){cin >> a[i];idx[a[i]] = i;}map<int, set<int>> mp;for (int i = 1; i <= m; i++){cin >> b[i];mp[b[i]].insert(i);}for (int i = 1; i <= n; i++){if (!mp.count(a[i])){mp[a[i]].insert(inf);}s[i] = *mp[a[i]].begin();}s[n + 1] = inf;set<int> st;for (int i = 1; i <= n; i++){if (s[i] > s[i + 1]){st.insert(i);}}if (!st.size()){cout << "YA" << endl;}elsecout << "TIDAK" << endl;while (q--){int id, t;cin >> id >> t;int res = idx[b[id]];mp[b[id]].erase(mp[b[id]].find(id));if (mp[b[id]].size())s[res] = *(mp[b[id]].begin());elses[res] = inf;if (st.count(res))st.erase(res);if (res > 1 && st.count(res - 1))st.erase(res - 1);if (s[res] > s[res + 1])st.insert(res);if (s[res - 1] > s[res] && res > 1)st.insert(res - 1);b[id] = t;res = idx[t];mp[t].insert(id);s[res] = *mp[t].begin();if (st.count(res))st.erase(res);if (res > 1 && st.count(res - 1))st.erase(res - 1);if (s[res] > s[res + 1])st.insert(res);if (s[res - 1] > s[res] && res > 1)st.insert(res - 1);if (!st.size()){cout << "YA" << endl;}elsecout << "TIDAK" << endl;}
}
signed main()
{ios::sync_with_stdio(false);cin.tie(0), cout.tie(0);int test = 1;cin >> test;for (int i = 1; i <= test; i++){solve();}return 0;
}

http://www.mrgr.cn/news/44148.html

相关文章:

  • 老房翻新,弱配电箱需不需要加?
  • 【Rust练习】17.泛型
  • 音质好且平价的开放式耳机排行榜10强?分享值得安利的蓝牙耳机
  • 留存率的定义与SQL实现
  • 物理学基础精解【56】
  • 新机配置Win11
  • Vue入门-指令学习-v-else和v-else-if
  • jsencrypt实现js加密的另外一种方式(使用node-jsencrypt库)
  • 【AI知识点】归一化(Normalization)
  • 前端的全栈混合之路Meteor篇:开发环境的搭建 -全局安装或使用docker镜像
  • Qt开发技巧(十五)字符串去除空格,跨网段搜索不生效,设置图片显示失败问题,表格视图的批量删除,主动判断字串编码,开启向前查询的属性,画家类载入html来绘制
  • Leecode热题100-560.和为k的子数组
  • 【玩转 JS 函数式编程_008】3.1.2 JavaScript 函数式编程筑基之:箭头函数——一种更流行的写法
  • MATLAB智能优化算法-学习笔记(4)——灰狼优化算法求解旅行商问题【过程+代码】
  • 基于SSM的学生信息管理系统【附源码】
  • Cyber Weekly #27
  • YOLOv8 基于NCNN的安卓部署
  • 上海交通大学《2022年+2023年816自动控制原理真题》 (完整版)
  • [git] github管理项目之环境依赖管理
  • 社会工程学:社工无处不在