首页 > 其他分享 >ROIR 2024

ROIR 2024

时间:2024-10-10 19:43:47浏览次数:1  
标签:count 2024 begin int ROIR MAXN && empty

B. 双调序列

题目描述

我们定义一个序列 \(X\) 是双调的当且仅当:

  • \(\exist 1\le i\le N,满足 X_1<X_2<\dots<X_i>\dots>X_N\)。

求序列 \(A\) 有多少个子串是双调的。

思路

可以发现,一个序列 \(X\) 是双调的当且仅当 \(X_1\ne X_2\ne \dots\ne X_N\and[X_1>X_2]\le[X_2>X_3]\le \dots\le [X_{N-1}>X_{N}]\)。

使用双指针求解即可。

时空复杂度均为 \(O(N)\)。

代码

#include<bits/stdc++.h>
using namespace std;
using ll = long long;

const int MAXN = 300001;

int n, a[MAXN];
ll ans;

int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for(int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  for(int i = 1, j = 1; i <= n; ++i) {
    for(; j <= n && (j == i || a[j] != a[j - 1]) && (j <= i + 1 || (a[j - 1] > a[j]) >= (a[j - 2] > a[j - 1])); ++j) {
    }
    ans += j - i;
  }
  cout << ans;
  return 0;
}

D. Adjust The Presentation (Easy Version)

题目描述

这是问题的简单版本。在两个版本中只有 \(q\) 的数据范围不同。在这个版本中 \(q=0\)。

有 \(N\) 个人按照 \(A_1,A_2,\dots,A_N\) 的顺序排成一排。

有 \(M\) 张幻灯片,每次你会让排头的人展示当前幻灯片,并切换到下一个幻灯片,接着把这个人插入到队列的任意位置。

给定序列 \(B_1,B_2,\dots,B_M\),你要判断是否有一种方法使得幻灯片 \(i\) 被第 \(B_i\) 个人展示。

有 \(q\) 次操作,每次操作会修改 \(B_s\leftarrow t\),并让你判断是否可行。

思路

这里显然有以下几种情况不合法:

  • 第 \(A_i\) 个人没有播放过幻灯片,但 \(A_{i+1}\) 播放了。
  • 第 \(A_i\) 个人第一次展示幻灯片的时间比 \(A_{i+1}\) 晚。

时空复杂度均为 \(O(N+M)\)。

代码

#include<bits/stdc++.h>
using namespace std;

const int MAXN = 200001;

int t, n, m, q, a[MAXN], b[MAXN], pos[MAXN];

void Solve() {
  cin >> n >> m >> q;
  for(int i = 1, x; i <= n; ++i) {
    cin >> x;
    a[x] = i;
    pos[i] = MAXN;
  }
  for(int i = 1, x; i <= m; ++i) {
    cin >> b[i];
    b[i] = a[b[i]];
    if(!pos[b[i]]) {
      pos[b[i]] = i;
    }
  }
  S.clear();
  for(int i = 1; i < n; ++i) {
    if(pos[i] > pos[i + 1]) {
      cout << "TIDAK\n";
      return;
    }
  }
  cout << "YA\n";
}

int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  for(cin >> t; t--; Solve()) {
  }
  return 0;
}

E. Adjust The Presentation (Hard Version)

题目描述

这是问题的简单版本。在两个版本中只有 \(q\) 的数据范围不同。在这个版本中 \(q\le2\cdot 10^5\)。

题目同上。

思路

通过上一题的思路,我们可以用 set \(s_i\) 记录下每个人 \(i\) 播放了哪些幻灯片,再用一个 set \(S\) 记录下不合法的 \(i\)。如果序列合法,则 \(S=\varnothing\)。

每次进行修改时,我们都把对应的 set 进行插入/删除,此时有两个 set 改变了,对对应的 \(x\) 再判断合法即可。

空间复杂度 \(O(N+M)\),时间复杂度 \(O(N+M\log M+Q\log M)\)。

代码

#include<bits/stdc++.h>
using namespace std;

const int MAXN = 200001;

int t, n, m, q, a[MAXN], b[MAXN];
set<int> s[MAXN], S;

void Solve() {
  cin >> n >> m >> q;
  for(int i = 1, x; i <= n; ++i) {
    cin >> x;
    a[x] = i;
    s[i].clear();
  }
  for(int i = 1, x; i <= m; ++i) {
    cin >> b[i];
    b[i] = a[b[i]];
    s[b[i]].insert(i);
  }
  S.clear();
  for(int i = 1; i < n; ++i) {
    if((s[i].empty() && !s[i + 1].empty()) || (!s[i].empty() && !s[i + 1].empty() && *s[i].begin() > *s[i + 1].begin())) {
      S.insert(i);
    }
  }
  cout << (S.empty() ? "YA\n" : "TIDAK\n");
  for(int i = 1, p, x; i <= q; ++i) {
    cin >> p >> x;
    x = a[x];
    int y = b[p];
    s[b[p]].erase(p);
    b[p] = x;
    s[b[p]].insert(p);
    if(x > 1) {
      if(S.count(x - 1) && !((s[x - 1].empty() && !s[x].empty()) || (!s[x - 1].empty() && !s[x].empty() && *s[x - 1].begin() > *s[x].begin()))) {
        S.erase(x - 1);
      }
      if(!S.count(x - 1) && ((s[x - 1].empty() && !s[x].empty()) || (!s[x - 1].empty() && !s[x].empty() && *s[x - 1].begin() > *s[x].begin()))) {
        S.insert(x - 1);
      }
    }
    if(x < n) {
      if(S.count(x) && !((s[x].empty() && !s[x + 1].empty()) || (!s[x].empty() && !s[x + 1].empty() && *s[x].begin() > *s[x + 1].begin()))) {
        S.erase(x);
      }
      if(!S.count(x) && ((s[x].empty() && !s[x + 1].empty()) || (!s[x].empty() && !s[x + 1].empty() && *s[x].begin() > *s[x + 1].begin()))) {
        S.insert(x);
      }
    }
    if(y > 1) {
      if(S.count(y - 1) && !((s[y - 1].empty() && !s[y].empty()) || (!s[y - 1].empty() && !s[y].empty() && *s[y - 1].begin() > *s[y].begin()))) {
        S.erase(y - 1);
      }
      if(!S.count(y - 1) && ((s[y - 1].empty() && !s[y].empty()) || (!s[y - 1].empty() && !s[y].empty() && *s[y - 1].begin() > *s[y].begin()))) {
        S.insert(y - 1);
      }
    }
    if(y < n) {
      if(S.count(y) && !((s[y].empty() && !s[y + 1].empty()) || (!s[y].empty() && !s[y + 1].empty() && *s[y].begin() > *s[y + 1].begin()))) {
        S.erase(y);
      }
      if(!S.count(y) && ((s[y].empty() && !s[y + 1].empty()) || (!s[y].empty() && !s[y + 1].empty() && *s[y].begin() > *s[y + 1].begin()))) {
        S.insert(y);
      }
    }
    cout << (S.empty() ? "YA\n" : "TIDAK\n");
  }
}

int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  for(cin >> t; t--; Solve()) {
  }
  return 0;
}

标签:count,2024,begin,int,ROIR,MAXN,&&,empty
From: https://www.cnblogs.com/yaosicheng124/p/18456997

相关文章

  • 2024CSP-J模拟赛————S12678
    禁止抄袭!!!一,赛中得分硬币(coin)100数位(digit)100划分(partition)0路径(path)0总分200二,赛中概括第一第二题30分钟做完,三四题不会。三,题目解析硬币(coin)1.1问题描述小明很喜欢 100这个数字,父母给他一些零花钱,这些零花钱的面值是 a 和 b,即小明......
  • 20222305 2024-2025-1 《网络与系统攻防技术》实验一实验报告
    网络攻防实验报告姓名:田青学号:20222305实验日期:2024/09/29—2024/10/09实验名称:缓冲区溢出和shellcode指导教师:王志强1.实验内容本周学习内容总结:学习了系统安全(缓冲区溢出是重点)主要内容:漏洞简介:定义以及安全漏洞。BOF(缓冲区溢出):直接原因-没有严格的内存越界检查......
  • 2024.9.30 CSP
    模拟赛赛后看着分哗啦啦的往下掉。T1median找中位数,赛时假做法A了,没想到直接搜。。。code#include<bits/stdc++.h>usingnamespacestd;constintN=1e5+5,mod=998244353;intn;inta[6][N],ans,f[6][4];unordered_map<int,bool>mp;intdfs(intp,intl,int......
  • 《从技术洞察到技术规划赋能培训》(2024年11月8-9日)
     【课程背景】所谓技术洞察,简称(TI,TechnologyInsight),是根据市场发展趋势和客户需求,以及技术的生命周期,对某项技术发展趋势进行判断和预测,并明确未来3~5年的技术战略和战略控制点、重大的技术投资方向,完成技术战略规划的制订,并最终进行技术战略解码,为公司整体战略创造价值。技......
  • [赛记] 多校A层冲刺NOIP2024模拟赛04
    这场ACCODERS忘交,结果最后想起来匆匆只交了T1,然后文件名还没改,所以爆零了。。。02表示法100pts高精度,不说了;点击查看代码#include<iostream>#include<cstdio>#include<string>#include<cmath>#include<algorithm>usingnamespacestd;stringp[605];stringan......
  • 2024激活Typora,最新版本的1.9.5可用
    目前最新版本 1.9.5也是可以实现激活的注:免修改注册表、不用修改时间,更不需要破解补丁01、下载&安装Typora从官网下载最新版本的Typora,并安装02、激活Typora找到Typora安装目录,依次找到这个文件resources\page-dist\static\js\LicenseIndex.**********.********.chunk.js......
  • 2024.9.25 多校 模拟赛
    模拟赛假做法上大分。T1几何bitset优化dp。有空学,先挂个暴力。code#include<bits/stdc++.h>usingnamespacestd;constintN=5e5+5;intT,n,m,t;chars[N],x[55],y[55];unordered_map<int,unordered_map<int,bool>>f[N];unordered_map<int,unordered_map<i......
  • 2024.9.28 模拟赛 CSP6
    模拟赛单\(log\)双\(log\)不如三\(log\)。T1一般图最小匹配简单dp,水。\(O(n^2)\)其实也是可反悔贪心的板子,可以\(O(n\log(n))\)做。考虑排序后求差分数组,就变成不能选相邻的。然后就是可反悔贪心板子。用双向链表(记录前驱后继)维护,然后放进堆里。板dp#include<b......
  • 2024年9月国产数据库大事记-墨天轮
    本文为墨天轮社区整理的2024年9月国产数据库大事件和重要产品发布消息。目录2024年9月国产数据库大事记TOP102024年9月国产数据库大事记(时间线)产品/版本发布兼容认证代表厂商大事记厂商活动相关资料2024年9月国产数据库大事记TOP102024年9月国产数据库大事记(时间线......
  • 20222313 2024-2025-1《网络与系统攻防技术》实验一报告
    1.实验内容本次实践的对象是一个名为pwn1的linux可执行文件。该程序正常执行流程是:main调用foo函数,foo函数会简单回显任何用户输入的字符串。该程序同时包含另一个代码片段,getShell,会返回一个可用Shell。正常情况下这个代码是不会被运行的。我们实践的目标就是想办法运行这个......