2018-2019 ACM-ICPC, NEERC, Southern Subregional Contest, Qualification Stage

A. Coffee Break

排序之后优先队列搞一下就好了

//#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
const int MAXN = 2e5+7;
const int INF = 0x3f3f3f3f;
int n,m,d,pos[MAXN]; int main(){
____();
cin >> n >> m >> d;
vector<pair<int,int>> vec(n);
for(int i = 0; i < n; i++){
cin >> vec[i].first;
vec[i].second = i;
}
sort(vec.begin(),vec.end());
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> que;
int tot = 0;
que.push(make_pair(-INF,++tot));
for(auto &p : vec){
int id = p.second, w = p.first;
if(que.top().first+d>=w) que.push(make_pair(-INF,++tot));
auto pr = que.top();
que.pop();
pr.first = w;
pos[id] = pr.second;
que.push(pr);
}
cout << tot << endl;
for(int i = 0; i < n; i++) cout << pos[i] << ' '; cout << endl;
return 0;
}

B.Glider

如果到了一块区间,那么必然会走完这块区间

而且必然是从某一块区间的最左边开始的

所以枚举每一个区间,二分找到最右边的可以到达的区间,用前缀和维护一下

//#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
const int MAXN = 2e5+7;
int n,h,pref[MAXN];
pair<int,int> pr[MAXN];
void solve(){
cin >> n >> h;
for(int i = 1; i <= n; i++) cin >> pr[i].first >> pr[i].second;
for(int i = 2; i <= n; i++) pref[i] = pref[i-1] + pr[i].first - pr[i-1].second;
int ret = 0;
for(int i = 1; i <= n; i++){
int l = i, r = n;
while(l<=r){
int mid = (l+r) >> 1;
if(pref[mid] - pref[i] < h) l = mid + 1;
else r = mid - 1;
}
ret = max(ret,pr[r].second - pr[i].first + 1 + h - (pref[r] - pref[i]) - 1);
}
cout << ret << endl;
}
int main(){
____();
solve();
return 0;
}

C.Bacteria

除gcd之后判断是否是\(2\)的次方

然后全部加和不断加\(lowbit\)直到变成\(2^x\)即可

//#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
const int MAXN = 2e5+7;
typedef long long int LL;
#define lowbit(x) (x&-x)
LL n,A[MAXN];
int main(){
____();
cin >> n;
for(int i = 1; i <= n; i++) cin >> A[i];
LL g = 0; for(int i = 1; i <= n; i++) g = __gcd(g,A[i]);
for(int i = 1; i <= n; i++) A[i] /= g;
for(int i = 1; i <= n; i++) if(__builtin_popcount(A[i])!=1){
cout << -1 << endl;
return 0;
}
LL tot = accumulate(A+1,A+1+n,0ll);
int ret = 0;
while(tot!=lowbit(tot)) tot += lowbit(tot), ret++;
cout << ret << endl;
return 0;
}

D.Masquerade strikes back

对于每个数找出所有因子,然后组合一下

//#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
const int MAXN = 2e5+7;
int n;
pair<int,int> A[MAXN],ret[MAXN];
vector<int> prime;
bool npm[MAXN];
void sieve(){
for(int i = 2; i < MAXN; i++){
if(!npm[i]) prime.push_back(i);
for(int j = 0; j < (int)prime.size(); i++){
if(i*prime[j]>=MAXN) break;
npm[i*prime[j]] = true;
if(i%prime[j]==0) break;
}
}
}
vector<pair<int,int> > getfact(int x){
map<int,int> fct;
for(int i = 0; prime[i] * prime[i] <= x; i++){
int &p = prime[i];
while(x%p==0){
fct[p]++;
x /= p;
}
if(x==1) break;
}
if(x!=1) fct[x]++;
vector<pair<int,int> > vec;
for(auto &p : fct) vec.push_back(p);
return vec;
}
void dfs(int pos, vector<pair<int,int> > &vec, vector<int> &vc, int &cnt, int prod){
if(pos==(int)vec.size()){
vc.push_back(prod);
cnt--; return;
}
for(int i = 0; i <= vec[pos].second; i++){
if(i) prod *= vec[pos].first;
dfs(pos+1,vec,vc,cnt,prod);
if(!cnt) return;
}
}
int main(){
____();
sieve();
cin >> n;
for(int i = 1; i <= n; i++) cin >> A[i].first;
for(int i = 1; i <= n; i++) A[i].second = i;
sort(A+1,A+1+n);
for(int i = 1, r; i <= n; i = r + 1){
r = i;
while(r<n and A[r+1].first==A[i].first) r++;
int num = r - i + 1;
if(A[i].first==1){
if(num>1){
cout << "NO" << endl;
return 0;
}
else{
ret[A[i].second] = make_pair(1,1);
continue;
}
}
vector<pair<int,int> > vec = getfact(A[i].first);
int tot = 1;
for(auto &pr : vec) tot = tot * (pr.second + 1);
if(tot<num){
cout << "NO" << endl;
return 0;
}
vector<int> vc;
dfs(0,vec,vc,num,1);
for(int j = i; j <= r; j++) ret[A[j].second] = make_pair(vc[j-i],A[i].first/vc[j-i]);
}
cout << "YES" << endl;
for(int i = 1; i <= n; i++) cout <<ret[i].first << ' ' << ret[i].second << endl;
return 0;
}

E.Painting the Fence

线段树区间置值

重复出现的修改只需要改一次

//#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
const int MAXN = 3e5+7;
int n,m,A[MAXN],vis[MAXN];
vector<int> pos[MAXN];
struct SegmentTree{
int l[MAXN<<2],r[MAXN<<2],col[MAXN<<2];
#define ls(rt) rt << 1
#define rs(rt) rt << 1 | 1
void build(int L, int R, int rt = 1){
l[rt] = L, r[rt] = R;
if(L+1==R){
col[rt] = A[L];
return;
}
int mid = (L+R) >> 1;
build(L,mid,ls(rt)); build(mid,R,rs(rt));
}
void pushdown(int rt){
if(!col[rt]) return;
col[ls(rt)] = col[rs(rt)] = col[rt];
col[rt] = 0;
}
void update(int L, int R, int c, int rt = 1){
if(L>=r[rt] or l[rt]>=R) return;
if(L<=l[rt] and r[rt]<=R){
col[rt] = c;
return;
}
pushdown(rt);
update(L,R,c,ls(rt)); update(L,R,c,rs(rt));
}
int query(int pos, int rt = 1){
if(l[rt] + 1 == r[rt]) return col[rt];
pushdown(rt);
int mid = (l[rt] + r[rt]) >> 1;
if(pos<mid) return query(pos,ls(rt));
else return query(pos,rs(rt));
}
}ST;
int main(){
scanf("%d",&n);
for(int i = 1; i <= n; i++){
scanf("%d",&A[i]);
pos[A[i]].push_back(i);
}
scanf("%d",&m);
ST.build(1,MAXN);
for(int i = 1; i <= m; i++){
int op; scanf("%d",&op);
if(vis[op]) continue;
vis[op] = true;
int lmax = 0x3f3f3f3f, rmax = 0;
for(auto p : pos[op]) if(ST.query(p)==op) lmax = min(lmax,p), rmax = max(rmax,p);
if(lmax>=rmax) continue;
ST.update(lmax,rmax+1,op);
}
for(int i = 1; i <= n; i++) printf("%d ",ST.query(i));
puts("");
return 0;
}

F.Tickets

前缀和

//#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
const int MAXN = 1e6+7;
const int D = 30;
int n,pre[MAXN][D]; int calc(int x){
int l = x / 1000;
int r = x % 1000;
int ret = 0;
while(l) ret += l % 10, l /= 10;
while(r) ret -= r % 10, r /= 10;
return abs(ret);
}
void preprocess(){
pre[0][0] = 1;
for(int i = 1; i < 1000000; i++){
int x = calc(i);
for(int j = 0; j < D; j++) pre[i][j] = pre[i-1][j];
pre[i][x]++;
}
}
void solve(){
int x; cin >> x;
int ret = 0, v = calc(x);
for(int i = 0; i < v; i++) ret += pre[x][i];
cout << ret << endl;
}
int main(){
____();
preprocess();
for(cin >> n; n; n--) solve();
return 0;
}

G.Tree Reconstruction

拉成一条链即可

//#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
const int MAXN = 1111;
set<int> S;
int n;
pair<pair<int,int>,int> pr[MAXN];
pair<int,int> ret[MAXN];
int main(){
____();
cin >> n;
for(int i = 1; i < n; i++) cin >> pr[i].first.first >> pr[i].first.second;
for(int i = 1; i < n; i++) if(pr[i].first.first>pr[i].first.second) swap(pr[i].first.first,pr[i].first.second);
for(int i = 1; i < n; i++){
if(pr[i].first.second!=n){
cout << "NO" << endl;
return 0;
}
pr[i].second = i;
}
sort(pr+1,pr+n);
for(int i = 1; i <= n; i++) S.insert(i);
int maxx = 0;
vector<int> vec;
for(int i = 1; i < n; i++){
if(pr[i].first.first>maxx){
vec.push_back(pr[i].first.first);
S.erase(pr[i].first.first);
maxx = pr[i].first.first;
}
else{
int u = *S.begin();
S.erase(S.begin());
if(u>pr[i].first.first){
cout << "NO" << endl;
return 0;
}
vec.push_back(u);
}
}
vec.push_back(n);
cout << "YES" << endl;
for(int i = 1; i < n; i++) ret[pr[i].second] = make_pair(vec[i-1],vec[i]);
for(int i = 1; i < n; i++) cout << ret[i].first << ' ' << ret[i].second << endl;
return 0;
}

H.Theater Square

简单计算一下

//#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
int n,m,x1,y1,x2,y2;
int main(){
____();
cin >> n >> m >> x1 >> y1 >> x2 >> y2;
cout << ((x1 - 1 + n - x2) * (m%2) + (x2-x1+1) * ((y1-1)%2 + (m-y2)%2) + 1) / 2 << endl;
return 0;
}

I.Heist

签到

//#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
int n,A[1111];
int main(){
____();
cin >> n;
for(int i = 1; i <= n; i++) cin >> A[i];
cout << *max_element(A+1,A+1+n) - *min_element(A+1,A+1+n) + 1 - n << endl;
return 0;
}

J.Buying a TV Set

除gcd之后取长宽最小倍数

//#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
typedef long long int LL;
LL a,b,x,y;
int main(){
____();
cin >> a >> b >> x >> y;
LL d = __gcd(x,y);
x /= d; y /= d;
cout << min(a/x,b/y) << endl;
return 0;
}

K.Medians and Partition

大于等于\(m\)的变成\(1\)

小于\(m\)的变成\(-1\)

然后贪心分段,保证分段之后前后依然是\(m\ good\)的

//#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
const int MAXN = 5e3+7;
int n,m,A[MAXN],pref[MAXN];
int main(){
____();
cin >> n >> m;
for(int i = 1; i <= n; i++) cin >> A[i];
for(int i = 1; i <= n; i++){
if(A[i]>=m) A[i] = 1;
else A[i] = -1;
}
for(int i = 1; i <= n; i++) pref[i] = pref[i-1] + A[i];
if(pref[n]<=0){
cout << 0 << endl;
return 0;
}
int last = 0, num = 1;
for(int i = 1; i <= n; i++){
if(pref[i]-pref[last]>0 and pref[n] - pref[i]>0){
num++;
last = i;
}
}
cout << num << endl;
return 0;
}

L.Ray in the tube

2018-2019 ACM-ICPC, NEERC, Southern Subregional Contest, Qualification Stage(11/12)的更多相关文章

  1. 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage

    2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage A. Union of Doubly Link ...

  2. 2019.04.18 第六次训练 【2018-2019 ACM-ICPC, NEERC, Southern Subregional Contest, Qualification Stage】

    题目链接: https://codeforces.com/gym/101911 又补了set的一个知识点,erase(it)之后it这个地址就不存在了,再引用的话就会RE A: ✅ B:  ✅ C: ...

  3. D. Dog Show 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred)

    http://codeforces.com/contest/847/problem/D 巧妙的贪心 仔细琢磨... 像凸包里的处理 #include <cstdio> #include & ...

  4. 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred)

    题目链接:http://codeforces.com/problemset/problem/847/I I. Noise Level time limit per test 5 seconds mem ...

  5. 2018-2019 ICPC, NEERC, Southern Subregional Contest

    目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...

  6. Codeforces 2018-2019 ICPC, NEERC, Southern Subregional Contest

    2018-2019 ICPC, NEERC, Southern Subregional Contest 闲谈: 被操哥和男神带飞的一场ACM,第一把做了这么多题,荣幸成为7题队,虽然比赛的时候频频出锅 ...

  7. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror) Solution

    从这里开始 题目列表 瞎扯 Problem A Find a Number Problem B Berkomnadzor Problem C Cloud Computing Problem D Gar ...

  8. 2018.10.20 2018-2019 ICPC,NEERC,Southern Subregional Contest(Online Mirror, ACM-ICPC Rules)

    i207M的“怕不是一个小时就要弃疗的flag”并没有生效,这次居然写到了最后,好评=.= 然而可能是退役前和i207M的最后一场比赛了TAT 不过打得真的好爽啊QAQ 最终结果: 看见那几个罚时没, ...

  9. Codeforces1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)总结

    第一次打ACM比赛,和yyf两个人一起搞事情 感觉被两个学长队暴打的好惨啊 然后我一直做傻子题,yyf一直在切神仙题 然后放一波题解(部分) A. Find a Number LINK 题目大意 给你 ...

随机推荐

  1. thinkphp redis实现文章点赞功能并同步入mysql

    <?php namespace app\common\controller; use think\App; use think\facade\Cache; use think\facade\Db ...

  2. Manjaro Linux 5.9.11-3安装和配置全局截图工具FlameShot教程

    背景说明 截图工具是日常适用频率较高的一种系统工具,在Linux下也有不少常用截图工具,如deepin-screenshot等,但是今天我们要介绍的是FlameShot--一款更加精致的Linux全局 ...

  3. wmic process进程管理

    process    进程管理工具 示例:1.列举当前的进程.进程路径.命令行.进程ID.父进程ID.线程数,内存使用::wmic process get name,executablepath,co ...

  4. .NET 项目中的单元测试

    .NET 项目中的单元测试 Intro "不会写单元测试的程序员不是合格的程序员,不写单元测试的程序员不是优秀的工程师." -- 一只想要成为一个优秀程序员的渣逼程序猿. 那么问题 ...

  5. 在.NET Core 中实现健康检查

    .NET Core中提供了开箱即用的运行状况检查,首先,我将在.NET Core API应用程序中执行运行状况检查,接下来,我们将使用DbContext集成SQL Server或数据库的运行状况检查, ...

  6. [APUE] 进程环境

    APUE 一书的第七章学习笔记. 进程终止 有 8 种方式可以使得进程终止,5 种为正常方式: Return from main Calling exit() Calling _exit or _Ex ...

  7. echarts图表X轴文字过长解决解决方案:根据文字长度自动旋转

    Echarts 标签中文本内容太长的时候怎么办 ? 关于这个问题搜索一下,有很多解决方案.无非就是 省略(间隔显示).旋转文字方向.竖排展示 前面两种解决方案,就是echarts暴露的: {   ax ...

  8. SpringBoot深入理解

    SpringBoot深入理解 项目打包SpringBoot启动过程 当使用打包时,会下载org-springframework-boot-loader的jar,并且不会放在lib存放的第三方jar包文 ...

  9. 苹果 M1 芯片 OpenSSL 性能测试

    Apple M1(MacBook Air 2020) type 16 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes md2 0.00 0.00 0.00 ...

  10. slice 切片实现 Slice object interface

    1.Python切片对象可以为任意类型 https://github.com/python/cpython/blob/master/Include/sliceobject.h /* Slice obj ...