8.17-407-模拟考
8.17-407-模拟考
分数
| 总分:364 | 转变 | 真实社交 | 落落的去维护数组 | 交叉区间 | 课前测:敲鼓 |
|---|---|---|---|---|---|
| 分数 | 100 | 50 | 74 | 40 | 100 |
T1 转变
题意分析
::::info[题意简化]{open}
给你一串数,让你把前
这一题第一眼看成了双端队列,但仔细一想,我们只要从第
| 注意特判 |
|---|
代码
::::success[代码]
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N=105;
int n,k;
int a[N];
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>k;
for(int i=1;i<=n;i++){
cin>>a[i];
}
if(k>n){
for(int i=1;i<=n;i++){
cout<<0<<' ';
}
return 0;
}
for(int i=k+1;i<=n;i++){
cout<<a[i]<<' ';
}
for(int i=1;i<=k;i++){
cout<<0<<' ';
}
return 0;
}
::::
T2 真实社交
题意分析
死因
::::warning[死因]{open}
不是,
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N=1e4+5;
int n,q;
bool G[N][N];
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>q;
while(q--){
int op,x,y;
cin>>op>>x>>y;
if(op==1){
G[x][y]=1;
}else if(op==2){
G[x][y]=0;
}else{
if(G[x][y]==1&&G[y][x]==1){
cout<<"Yes"<<endl;
}else{
cout<<"No"<<endl;
}
}
}
return 0;
}
::::
题意分析
::::info[题意简化]{open}
有
| 第一眼看成了图,结果看到数据直接劝退,其实我们可以用 |
|---|
代码
::::success[代码]
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N=1e4+5;
int n,q;
map<pair<int,int>,int> mp;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>q;
while(q--){
int op,x,y;
cin>>op>>x>>y;
if(op==1){
mp[{x,y}]=1;
}else if(op==2){
if(mp.count({x,y})){
mp.erase({x,y});
}
}else{
if(mp.count({x,y})&&mp.count({y,x})){
cout<<"Yes"<<endl;
}else{
cout<<"No"<<endl;
}
}
}
return 0;
}
::::
T3 落落的去维护数组
死因
::::warning[死因]{open} 写暴力,结果大数据炸飞了。 :::: ::::warning[错误代码]
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N=2e5+5;
int n,q;
int a[N];
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
cin>>q;
while(q--){
int op;
cin>>op;
if(op==1){
int k;
cin>>k;
for(int i=1;i<=n;i++){
a[i]=k;
}
}else if(op==2){
int i,k;
cin>>i>>k;
a[i]+=k;
}else{
int i;
cin>>i;
cout<<a[i]<<endl;
}
}
return 0;
}
::::
题意分析
::::info[题意简化]{open}
我们可以定义一个
操作为1时,