比赛 |
EYOI与SBOI开学欢乐赛13th |
评测结果 |
AAAATTTTTT |
题目名称 |
WHZ 的序列 |
最终得分 |
40 |
用户昵称 |
qyd |
运行时间 |
6.966 s |
代码语言 |
C++ |
内存使用 |
6.53 MiB |
提交时间 |
2022-10-21 21:21:21 |
显示代码纯文本
- #include<iostream>
- using namespace std;
- #define ll long long
- ll a[200001];
- ll s=0;
- void oprst(int l,int r,int d);
- void oprnd(int l,int r);
- int main()
- {
- freopen("whz_sequence.in","r",stdin);
- freopen("whz_sequence.out","w",stdout);
-
- int n,q;
- cin>>n;
-
- for(int i=1;i<=n;i++)
- cin>>a[i];
-
- cin>>q;
-
- while(q)
- {
- q--;
- int opt;
- cin>>opt;
-
- if(opt==1)
- {
- int l,r,d;
- cin>>l>>r>>d;
- oprst(l,r,d);
- }
-
- if(opt==2)
- {
- int l,r;
-
- cin>>l>>r;
- oprnd(l,r);
- cout<<s<<endl;
- }
- }
-
- return 0;
- }
- void oprst(int l,int r,int d)
- {
- for(int i=l;i<=r;i++)
- a[i]+=d;
-
- return ;
- }
- void oprnd(int l,int r)
- {
- s=0;
- int i=1;
- for(int k=l;k<=r;k++)
- {
- s+=i*a[k];
- i*=(-1);
- }
-
- return ;
- }