cf C. Levko and Array Recovery
2014-08-28 19:27
295 查看
http://codeforces.com/contest/361/problem/C
这道题倒着一次,然后正着一次,在正着的一次的时候判断合不合法就可以。
View Code
这道题倒着一次,然后正着一次,在正着的一次的时候判断合不合法就可以。
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int inf=100000000; int p[1000001],ans[1000001]; int t[1000001],l[1000001],r[1000001],d[1000001]; int n,m; int flag; int main() { while(scanf("%d%d",&n,&m)!=EOF) { for(int i=1; i<=n; i++) { ans[i]=inf; } for(int i=0; i<m; i++) { scanf("%d%d%d%d",&t[i],&l[i],&r[i],&d[i]); } for(int i=m-1; i>=0; i--) { if(t[i]==1) { for(int j=l[i]; j<=r[i]; j++) { ans[j]-=d[i]; } } else if(t[i]==2) { for(int j=l[i]; j<=r[i]; j++) { ans[j]=min(ans[j],d[i]); } } } for(int i=1; i<=n; i++) { p[i]=ans[i]; } bool flag1=false; for(int i=0; i<m; i++) { if(t[i]==1) { for(int j=l[i]; j<=r[i]; j++) { p[j]+=d[i]; } } else if(t[i]==2) { flag=0; for(int j=l[i]; j<=r[i]; j++) { if(p[j]==d[i]) flag=1; else if(p[j]>d[i]) { flag1=true; break; } } if(flag!=1) { flag1=true; break; } } } if(flag1) printf("NO\n"); else { printf("YES\n"); for(int i=1; i<=n; i++) { if(i==1) printf("%d",ans[i]); else printf(" %d",ans[i]); } printf("\n"); } } return 0; }
View Code
相关文章推荐
- CF-Codeforces Round #210 (Div. 1)-A-Levko and Array Recovery
- Codeforces 361C - Levko and Array Recovery(贪心)
- Codeforces Round #210 (Div. 2) C. Levko and Array Recovery
- A. Levko and Array Recovery----思维题
- CodeForces 360A - Levko and Array Recovery (模拟)
- Codeforces Round #210 (Div. 2) C. Levko and Array Recovery && Codeforces 360 A 详解(思维+维护理论值)
- CodeForces 360A - Levko and Array Recovery (思维)
- cf D. Levko and Array
- CodeForces - 361C A - Levko and Array Recovery 思维
- CF 360B - Levko and Array (二分+dp)
- CodeForces 360A - Levko and Array Recovery 给出操作求原始数列
- CF 439C(251C题)Devu and Partitioning of the Array
- CodeForces 360 B.Levko and Array(二分+dp)
- Codeforces #360B: Levko and Array 题解
- CF:Eugeny and Array
- B. Levko and Array----二分答案
- B. Levko and Array
- CF 439C(251C题)Devu and Partitioning of the Array
- Codeforces Round #210 (Div. 1) B. Levko and Array(dp 思维)
- CF 295A - Greg and Array 差分數列