Submission #867298

# Submission time Handle Problem Language Result Execution time Memory
867298 2023-10-28T06:37:18 Z Faisal_Saqib Nuclearia (CEOI15_nuclearia) C++17
15 / 100
1000 ms 347884 KB
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <iostream>
#include <algorithm>
#include <climits>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
#include <fstream>
using namespace std;
 
#define vll vector<ll>
#define sll set<ll>
#define vstr vector<string>
#define ll long long
#define ld long double
#define supra main
#define pb push_back
#define add insert
#define rall(x) rbegin(x),rend(x)
#define all(x) (x).begin(),(x).end()
#define I ios_base::sync_with_stdio(false);
#define Hear cin.tie(NULL);
#define Shots cout.tie(NULL);
#define Ratatatata
ll powmod(ll a,ll b,ll modulo)
{
  if(b==0){
    return 1;
  }
  ll temp=powmod(a,b/2,modulo);
  if(b%2==0){
    return (temp*temp)%modulo;
  }
  else{
    return (a*((temp*temp)%modulo))%modulo;
  }
}
 
bool Prime(ll n){
    if (n <= 1)
        return false;
    for (ll i = 2; i <= sqrt(n); i++)
        if (n % i == 0)
            return false;
 
    return true;
}
inline ll read() {
    ll c;
    scanf("%lld",&c);
    return c;
}
struct SegmentTree
{
    ll sum=0,lazy=0;
    SegmentTree* next[2];
    ll s,e;
    SegmentTree(ll l,ll r)
    {
        s=l;
        e=r;
        if(s!=e)
        {
            ll mid=(s+e)/2;
            next[0]=new SegmentTree(s,mid);
            next[1]=new SegmentTree(mid+1,e);
        }
    }
    inline void push()
    {
        if(!lazy)
            return;
        sum+=(e-s+1)*lazy;
        if(s!=e)
        {
            next[0]->lazy+=lazy;
            next[1]->lazy+=lazy;
        }
        lazy=0;
    }
    inline void Update(ll& l,ll& r,ll& val)
    {
        push();
        if(e<l or r<s)
            return;
        if(l<=s and e<=r)
        {
            lazy+=val;
            push();
            return;
        }
        next[0]->Update(l,r,val);
        next[1]->Update(l,r,val);
        sum=next[0]->sum+next[1]->sum;
    }
    inline ll get(ll& l,ll& r)
    {
        push();
        if(e<l or r<s)
        {
            return 0;
        }
        if(l<=s and e<=r)
        {
            return sum;
        }
        ll ans=next[0]->get(l,r)+next[1]->get(l,r);
        sum=next[0]->sum+next[1]->sum;
        return ans;
    }
};
SegmentTree* dif;
ll n,m;
void Call_Me_When_You_Want(ll& l,ll& r,ll& cur,ll& add)
{
    if(r<l)
    {
        return;
    }
    // dif[l]+=cur;
    // dif[l+1]+=add;
    // dif[r]+=add;
    // dif[r+1]-=(cur+(add*(r-l)))
    // a[l]+=cur;
    // a[l+1]+=cur+add;
    //  |    += |
    // a[r]+=cur+(add*(r-l))
    // cout<<"Adding "<<cur<<" To range "<<l<<' '<<l<<endl;
    dif->Update(l,l,cur);
    // for(int i=1;i<=m;i++)
    // {
    //     cout<<dif->get(i,i)<<' ';;
    // }
    // cout<<endl;
    // cout<<"Adding "<<add<<" To range "<<l+1<<' '<<r<<endl;
    l++;
    dif->Update(l,r,add);
    l--;
    // for(int i=1;i<=m;i++)
    // {
    //     cout<<dif->get(i,i)<<' ';;
    // }
    // cout<<endl;
    // cout<<"Adding "<<-1*(cur+(r-l)*add)<<" To range "<<r+1<<' '<<r+1<<endl;
    r++;
    cur+=(r-l-1)*add;
    cur*=-1;
    dif->Update(r,r,cur);
    cur*=-1;
    cur-=(r-l-1)*add;
    r--;
    // for(int i=1;i<=m;i++)
    // {
    //     cout<<dif->get(i,i)<<' ';;
    // }
    // cout<<endl;
}
void solve()
{
    ll m=read(),n=read(),p=read();
    dif=new SegmentTree(1,m+1);
    for(int asp=0;asp<p;asp++)
    {
        ll j=read(),i=read(),final=read(),add=read();
        ll l=max(1ll,j-(final/add));
        ll cur=final-(add*(j-l));
        j--;
        Call_Me_When_You_Want(l,j,cur,add);
        j++;
        ll r=min(m,j+(final/add));
        add*=-1;
        Call_Me_When_You_Want(j,r,final,add);
    }
    vll pre={0};
    ll one=1;
    for(ll i=1;i<=m;i++)
    {
        pre.pb(pre.back()+dif->get(one,i));
    }
    ll q=read();
    while(q--)
    {
        ll y1=read(),x1=read(),y2=read(),x2=read();
        ll sum=0,cell=(y2-y1+1)*(x2-x1+1);
        sum=pre[y2]-pre[y1-1];
        ld cur=((ld)sum/(ld)cell);
        cur+=0.5;
        printf("%lld\n",(ll)(cur));
        // cout<<(ll)cur<<'\n';
    }
}
signed supra(){
    I Hear Shots Ratatatata
    // cout<<setprecision(1000);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ll tqwertyuiop=1;
    // cin>>tqwertyuiop;
    for(int tp=1;tp<=tqwertyuiop;tp++)
    {
        // cout<<"Case #"<<tp<<": ";
        solve();
    }
    return 0;
}

Compilation message

nuclearia.cpp: In function 'void solve()':
nuclearia.cpp:167:21: warning: unused variable 'i' [-Wunused-variable]
  167 |         ll j=read(),i=read(),final=read(),add=read();
      |                     ^
nuclearia.cpp:163:17: warning: unused variable 'n' [-Wunused-variable]
  163 |     ll m=read(),n=read(),p=read();
      |                 ^
nuclearia.cpp: In function 'long long int read()':
nuclearia.cpp:53:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |     scanf("%lld",&c);
      |     ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 529 ms 347884 KB Output is correct
2 Correct 65 ms 2640 KB Output is correct
3 Correct 66 ms 2344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 539 ms 347416 KB Output is correct
2 Correct 67 ms 2764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1116 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 609 ms 346832 KB Output is correct
2 Correct 70 ms 3152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 283 ms 135864 KB Output is correct
2 Correct 65 ms 2640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 69 ms 2116 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 181 ms 69500 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1102 ms 322344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1061 ms 317756 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 314 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 313 ms 2384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 189 ms 2052 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 296 ms 3156 KB Output isn't correct
2 Halted 0 ms 0 KB -