1. 程式人生 > >Codeforces Round #427 C

Codeforces Round #427 C

nod 求和 sta sync div namespace for ios cout

Star sky

題意:在坐標系上有一些星星,坐標大於1小於100,每顆星星初始亮度為si,每過1s亮度+1,當亮度>c的時候變為0,c<=10,q個詢問,求每次在給定的矩形區域內所有星星的亮度

思路:處理出每一個星星每個事件的亮度,然後再對應到坐標(一個坐標可能有多顆星星),處理出x或y軸的前綴和,每次詢問對區域內的亮度求和就是

AC代碼:

#include "iostream"
#include "string.h"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "set"
#include "map" #include "algorithm" #include "stdio.h" #include "math.h" #pragma comment(linker, "/STACK:102400000,102400000") #define ll long long #define endl ("\n") #define bug(x) cout<<x<<" "<<"UUUUU"<<endl; #define mem(a,x) memset(a,x,sizeof(a)) #define mp(x,y) make_pair(x,y) #define
pb(x) push_back(x) #define ft (frist) #define sd (second) #define lrt (rt<<1) #define rrt (rt<<1|1) using namespace std; const long long INF = 1e18+1LL; const int inf = 1e9+1e8; const int N=1e5+100; const ll mod=1e9+7; ///CCCC int n,q,c; int s[15][105][105]; struct Node{ int x,y,s; }; Node ar[
15][N]; int main(){ ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); cin>>n>>q>>c; int x,y,z; for(int i=1; i<=n; ++i){ cin>>x>>y>>z; ar[0][i].x=x, ar[0][i].y=y, ar[0][i].s=z; } for(int i=1; i<=c; ++i){ for(int j=1; j<=n; ++j){ ar[i][j]=ar[0][j]; } } for(int i=1; i<=c; ++i){ for(int j=1; j<=n; ++j){ ar[i][j].s+=i; ar[i][j].s%=c+1; } } for(int i=0; i<=c; ++i){ for(int j=1; j<=n; ++j){ x=ar[i][j].x, y=ar[i][j].y; s[i][x][y]+=ar[i][j].s; } } for(int i=0; i<=c; ++i){ for(int j=1; j<=100; ++j){ for(int k=2; k<=100; ++k){ s[i][j][k]+=s[i][j][k-1]; } } } int x1,y1,x2,y2,t; while(q--){ cin>>t>>x1>>y1>>x2>>y2; t%=c+1; ll ans=0; for(int i=x1; i<=x2; ++i){ ans += s[t][i][y2]-s[t][i][y1-1]; } cout<<ans<<endl; } return 0; }

Codeforces Round #427 C