传送门

废话不说,这道题暴力枚举是$O(N^6)$,显然无法承受。

推导一下

$(x_1*x_2+x_3)/x_4-x_5=x_6$

$x_1*x_2+x_3=x_4*(x_5+x_6)$

等式左边和右边的复杂度都是$O(N^3)$的,可以接受!

但是如果没开$O_2$不要用map,会被卡常,g++11的unorderded_map不错,但是大部分OJ并不滋次,建议手写hash,based要卡大点。

 //OJ 1869
 //by Cydiater
 //2016.9.13
 #include <iostream>
 #include <cstdio>
 #include <cstring>
 #include <queue>
 #include <map>
 #include <ctime>
 #include <cmath>
 #include <cstring>
 #include <string>
 #include <algorithm>
 #include <cstdlib>
 using namespace std;
 #define ll long long
 #define up(i,j,n)        for(ll i=j;i<=n;i++)
 #define down(i,j,n)        for(ll i=j;i>=n;i--)
 const ll oo=0x3f3f3f3f;
 ;
 ;
 inline ll read(){
     ,f=;
     ;ch=getchar();}
     +ch-';ch=getchar();}
     return x*f;
 }
 ll lable[];
 ll N,a[],ans=;
 struct HashTable{
     ll Value[];
     HashTable(){up(i,,mod+)Value[i]=-oo;}
     ll Hash_value(ll num){
         ll tmp=num;
         num%=mod;num+=mod;num%=mod;
         while(Value[num]!=tmp){
             if(Value[num]==-oo){
                 Value[num]=tmp;
                 return num;
             }
             num+=step;num%=mod;
         }
         return num;
     }
 }hash;
 namespace solution{
     void pret(){
         up(i,,N)up(j,,N)up(k,,N))lable[hash.Hash_value(a[i]*(a[j]+a[k]))]++;
     }
     void init(){
         N=read();
         up(i,,N)a[i]=read();
     }
     void slove(){
         up(i,,N),N),N)/*x_2*/
         ans+=lable[hash.Hash_value(a[i]+a[j]*a[k])];
     }
     void output(){
         cout<<ans<<endl;
     }
 }
 int main(){
     //freopen("input.in","r",stdin);
     using namespace solution;
     init();
     pret();
     slove();
     output();
     //cout<<"Time has passed:"<<1.0*clock()/1000<<"s!"<<endl;
     ;
 }

SPOJ:ABCDEF的更多相关文章

  1. Meet in the middle算法总结 (附模板及SPOJ ABCDEF、BZOJ4800、POJ 1186、BZOJ 2679 题解)

    目录 Meet in the Middle 总结 1.算法模型 1.1 Meet in the Middle算法的适用范围 1.2Meet in the Middle的基本思想 1.3Meet in ...

  2. SPOJ ABCDEF题解

    题面 源 OJ 未 AC(卡 \(map\) ,不想写 \(hash\) ). 看到 \(n \leq 100\) ,显然 \(O(n^6)\) 会挂掉,所以要优化. 考虑到原式可化为 \(a \ti ...

  3. OI卷题记录

    2021.8.2 LG3386 匈牙利算法 二分图 LG1377 笛卡尔树 题解 2021.8.3 LG2962 \(\text{Meet in middle}\) LG3389 高斯消元 高斯-约旦 ...

  4. BZOJ 2588: Spoj 10628. Count on a tree [树上主席树]

    2588: Spoj 10628. Count on a tree Time Limit: 12 Sec  Memory Limit: 128 MBSubmit: 5217  Solved: 1233 ...

  5. SPOJ DQUERY D-query(主席树)

    题目 Source http://www.spoj.com/problems/DQUERY/en/ Description Given a sequence of n numbers a1, a2, ...

  6. SPOJ GSS3 Can you answer these queries III[线段树]

    SPOJ - GSS3 Can you answer these queries III Description You are given a sequence A of N (N <= 50 ...

  7. 【填坑向】spoj COT/bzoj2588 Count on a tree

    这题是学主席树的时候就想写的,,, 但是当时没写(懒) 现在来填坑 = =日常调半天lca(考虑以后背板) 主席树还是蛮好写的,但是代码出现重复,不太好,导致调试的时候心里没底(虽然事实证明主席树部分 ...

  8. SPOJ bsubstr

    题目大意:给你一个长度为n的字符串,求出所有不同长度的字符串出现的最大次数. n<=250000 如:abaaa 输出: 4 2 1 1 1 spoj上的时限卡的太严,必须使用O(N)的算法那才 ...

  9. 【SPOJ 7258】Lexicographical Substring Search

    http://www.spoj.com/problems/SUBLEX/ 好难啊. 建出后缀自动机,然后在后缀自动机的每个状态上记录通过这个状态能走到的不同子串的数量.该状态能走到的所有状态的f值的和 ...

随机推荐

  1. IDEA 13 无法进入debug 模式解决方案

    1.最近在idea中使用tomcat开发项目,像往常一样打开tomcat进行debug,但奇怪的事情出现了,项目根本不进断点.后查找原因,估计idea的加载参数方式是:先加载tomcat中设置的参数, ...

  2. SQLite剖析之C/C++接口

    前言 SQLite3是SQLite一个全新的版本,它虽然是在SQLite2的代码基础之上开发的,但是使用了和之前的版本不兼容的数据库格式和API.SQLite3是为了满足以下的需求而开发的:支持UTF ...

  3. T4模板——一个神奇的代码生成器

    利用T4模板,可以很方便的从数据库映射成Model模型,相当于动软等功效.但动软是可以直接生成三层,抽象工厂的,T4没那么牛叉,所以我们一般只用作生成Modle或者Server等指定方法了. 废话少说 ...

  4. Java Little Knowledge

    1.Constructor running order of Base class and Derived class This is Alibaba's audition problem. clas ...

  5. 转:PHP中防止SQL注入的方法

    [一.在服务器端配置] 安全,PHP代码编写是一方面,PHP的配置更是非常关键. 我们php手手工安装的,php的默认配置文件在 /usr/local/apache2/conf/php.ini,我们最 ...

  6. window 安装redis服务、卸载redis服务和启动redis服务

    1.安装redis服务 redis-install.bat 1 echo install redis-server23 D:\redis\redis-server.exe --service-inst ...

  7. 腾讯云CentOS 安装MediaWiki

    参考 : https://www.digitalocean.com/community/tutorials/how-to-install-mediawiki-on-centos-7 //安装好很多次终 ...

  8. 个人阅读作业——M1/M2总结

    ~ http://www.cnblogs.com/wx1306/p/4831950.html 在这篇博客中,我提出来一些关于软件工程的问题,但随着这一个学期的即将结束,以及我对软件开发的了解的深入,我 ...

  9. Bete冲刺第六阶段

    Bete冲刺第六阶段 github:https://github.com/RadioGroup/JourneyHelper 今日工作: web: 陈灿:新增了用户信息更新接口,优化了部分接口逻辑,更新 ...

  10. RabbitMQ 工作队列

    创建一个工作队列用来在工作者(consumer)间分发耗时任务. 工作队列的主要任务是:避免立刻执行资源密集型任务,然后必须等待其完成.相反地,我们进行任务调度:我们把任务封装为消息发送给队列.工作进 ...