Submission #443719

# Submission time Handle Problem Language Result Execution time Memory
443719 2021-07-11T18:12:45 Z julian33 Bob (COCI14_bob) C++14
12 / 120
310 ms 17860 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {
    cerr<<vars<<" = ";
    string delim="";
    (...,(cerr<<delim<<values,delim=", "));
    cerr<<"\n";
}
#else
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {}
#endif

#define pb push_back
#define sz(x) (int)(x.size())
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> inline void maxa(T& a,T b){a=max(a,b);}
template<typename T> inline void mina(T& a,T b){a=min(a,b);} 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int mxN=1e3+5; //make sure this is right
const int mod=1e9+7;

int a[mxN][mxN],up[mxN][mxN];

struct BIT{
    ll bit[mxN]; 
    void init(){memset(bit,0,sizeof(bit));}
    void upd(int x,int v){while(x<mxN){bit[x]+=v;x+=x&-x;}}
    ll sum(int x){ll res=0;while(x){res+=bit[x];x-=x&-x;}return res;} 
};

BIT bit,bit2;

int main(){
    cin.sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    #ifdef LOCAL
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif

    int n,m; cin>>n>>m;
    ll ans=0;
    for(int i=1;i<=n;i++){
        bit.init(); bit2.init();
        for(int j=1;j<=m;j++){
            cin>>a[i][j];
            if(a[i][j]==a[i-1][j])
                up[i][j]=up[i-1][j]+1;
            else
                up[i][j]=1;
            if(a[i][j]!=a[i][j-1]){
                bit.init(); bit2.init();
            }
            bit.upd(up[i][j],1);
            bit2.upd(up[i][j],up[i][j]);
            ll s1=bit2.sum(up[i][j]);
            ll s2=bit.sum(n)-bit.sum(up[i][j]);
            ans+=s1+up[i][j]*s2;
        }
    }
    cout<<ans<<"\n";
}

# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 716 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 59 ms 4792 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 49 ms 5172 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 64 ms 5396 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 58 ms 5384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 275 ms 14784 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 310 ms 17824 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 251 ms 17660 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 245 ms 17860 KB Output isn't correct
2 Halted 0 ms 0 KB -